我正在开发一款App。在调用我的某个Web服务时,我收到了错误,
Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0x7f9200696fc0 {NSDebugDescription=Invalid value around character 0.}
这是我的代码: -
NSError *error;
NSURLResponse *response;
NSURL *post=[NSURL URLWithString:myUrl];
NSMutableURLRequest *request=[[NSMutableURLRequest alloc]initWithURL:post cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:50];
[request setHTTPMethod:@"POST"];
[request addValue:@"application/x-www-form-urlencoded;charset=utf-8" forHTTPHeaderField:@"Content-Type"];
NSString *body=[NSString stringWithFormat:@"userId=%@",userId];
[request setHTTPBody:[body dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (data==nil) {
return;
}
NSLog(@"data from JSON =%@",data);
当我打印我的NSData时,我在解析时遇到了一些错误,
<b>Parse error</b>: syntax error, unexpected end of file, expecting function (T_FUNCTION) in <b>/var/www
现在,我该怎么做才能解决这个问题?任何人都可以建议吗?
答案 0 :(得分:1)
检查http状态代码很重要,服务器可以返回特定于服务器的响应代码。
见Status Code Definitions。请注意,服务器许多齿定义了特定于应用程序的5xx错误代码。