Iam使用ASIHTTPRequest POST方法从服务器获取json直到昨天我能够从服务器获取json但是从昨天晚上起我没有从serverI获取任何东西试图在模拟器中运行代码然后从服务器获取json(我的互联网现在有点慢)。我确认服务器没有变化。
这是我的日志中的错误
Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred" UserInfo=0x170268400 {NSLocalizedDescription=A connection failure occurred, NSUnderlyingError=0x17005e4b0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error 2.)"}
这是我获取JSON的代码
- (void)fetchData
{
NSArray *keys = [NSArray arrayWithObjects:@"action", @"conferenceId", nil];
NSArray *objects = [NSArray arrayWithObjects:@"query", [NSNumber numberWithInt:1], nil];
NSDictionary *jsonDictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
NSString* jsonBody = [jsonDictionary JSONRepresentation];
NSLog(@"jsonBody%@",jsonBody);
NSURL *url = [NSURL URLWithString:@"http://exampleurl.com/query"];
_queryRequest = [ASIFormDataRequest requestWithURL:url];
[_queryRequest setPostValue:jsonBody forKey:@"queryJSON"];
NSLog(@"_queryRequest%@", [_queryRequest valueForKey:@"postData"]);
[_queryRequest setDelegate:self];
[_queryRequest setRequestMethod:@"POST"];
[_queryRequest startAsynchronous];
NSLog(@"startAsynchronous");
}
#pragma mark HTTPRequest Delegate Methods
- (void)requestStarted
{
NSLog(@"requestStarted");
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSString *responseString = [request responseString];
responseString = [responseString stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
NSLog(@"Response %d ==> %@", request.responseStatusCode, [request responseString]);
if (request == _queryRequest)
{
[self processQueryResponse:responseString];
}
}
- (void) requestFailed:(ASIHTTPRequest *)request {
NSLog(@"%@",request.error);
}
以下是_queryRequest变量的值
(
{
key = queryJSON;
value = "{\"action\":\"query\",\"conferenceId\":1}";
}
)
请帮助我,为什么它突然在设备上失败???