我正在尝试使用以下代码向我的服务器发送POST请求:
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方法,我不知道为什么:(,
我做错了什么?提前谢谢。