NSURLSession发送GET请求,即使我在列举HTTPMethod
问题描述:
我试图发送POST请求到我的服务器用下面的代码设置POST:NSURLSession发送GET请求,即使我在列举HTTPMethod
NSURLSessionConfiguration *defaultConfigObj = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration:defaultConfigObj];
//NSURL *url = [NSURL URLWithString:@"http://www.myserver.com/page.aspx"];
NSURL *url = [NSURL URLWithString:@"http://10.47.72.40/test/page.aspx"];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10.10f];
NSString *params = [NSString stringWithFormat:@"data=%@&UserMail=%@",
InfoDictionary[@"ID"],
arrDatosMail[0]
];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
NSURLSessionDataTask *dataTask = [defaultSession dataTaskWithRequest:urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSLog(@"Response: %@ error:%@", response, error);
if(error == nil){
NSString *textRepsonse = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Data: %@", textRepsonse);
}
}];
所以,与本地IP当一个尝试,它的工作原理罚款(服务器收到POST请求),但当我更改远程IP(de www.myserver.com/page.aspx)页面接收请求与GET方法,我不知道为什么:(,
我在做什么错了?提前致谢。
如何检查正在使用的HTTP方法? – 2015-01-15 17:25:46