【发布时间】:2014-01-20 18:30:31
【问题描述】:
我创建了一个包含“电子邮件”和“密码”字段的字典,并将这些参数用作我的请求正文。我从我的服务器收到我缺少参数电子邮件和密码的响应 - 我很肯定这不是服务器端的问题。这就是我形成请求的方式:
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSString *urlString = @"xxxxxx.xxxx.com/userServices/login";
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSDictionary *params = @{@"email" : email, @"password" : password};
NSData *bodyData = [NSJSONSerialization dataWithJSONObject:params options:NSJSONWritingPrettyPrinted error:nil];
[request setHTTPBody:bodyData];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[request setTimeoutInterval:45];
[request setHTTPShouldHandleCookies:NO];
知道为什么服务器无法识别我的参数吗?
【问题讨论】:
标签: ios http-post nsurlrequest