在POST方法中进行JSON解析后的响应,在iOS中给出代码状态400

时间:2014-04-25 05:56:05

标签: ios json http-post nsjsonserialization rest-client

我在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"];
}

0 个答案:

没有答案