我正在尝试使用以下代码向我的服务器发送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(使用www.myserver.com/page.aspx)时,页面使用GET方法接收请求,我不知道为什么:(,
我做错了什么?提前致谢。
没有问题。请求将作为POST发送。我建议使用代理调试确切发送的内容。在Mac上,Charles代理是一个很好的代理。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句