我在Objective C(iOS)中使用POST method
调用Web服务。我在NSUTF8StringEncoding
中对参数进行编码,然后将其嵌入到url中。我正在JSON format
得到答复。
但我得到的回应是:
<NSHTTPURLResponse: 0x8df87e0> { URL: http://local.server/Servi1.svc/Register } { status code: 400, headers { "Content-Length" = 1675; etc etc..... Date, Server n all}}
但是当我在Firefox REST Client
中请求时,POST方法中的URL相同,我得到了正确的答案。
任何人都可以帮助我吗?
{
NSString * strBodyOnlineStart = [NSString
stringWithFormat:@"mobile_key=%@&key=%@",key,strId];
urlOnlineStart = [NSURL
URLWithString:@"http://local.server/Servi1.svc/Register"];
NSMutableURLRequest *requestOnlineStart = [NSMutableURLRequest
requestWithURL:urlOnlineStart];
[requestOnlineStart setHTTPMethod:@"POST"];
NSData *requestBodyOnlineStart = [strBodyOnlineStart
dataUsingEncoding:NSUTF8StringEncoding];
[requestOnlineStart setHTTPBody:requestBodyOnlineStart];
NSURLResponse *responseOnlineStart = NULL;
NSError *requestErrorOnlineStart = NULL;
NSData *responseDataOnlineStart = [NSURLConnection
sendSynchronousRequest:requestOnlineStart returningResponse:&responseOnlineStart
error:&requestErrorOnlineStart];
NSDictionary *jsonDictOnlineStart = [NSJSONSerialization
JSONObjectWithData:responseDataOnlineStart options:kNilOptions error:nil];
arrayOfQuestions = [ jsonDictOnlineStart objectForKey:@"data"];
}