HTTP get方法获取空值

时间:2015-04-20 08:20:14

标签: ios objective-c json httprequest httpresponse

我正在使用HTTP get方法从url获取值,在url响应中获取但是对我来说值不是来可以任何人帮助我。以下是我的编码

 NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://www.gmasa.org/wp-json/posts?type=owl-carousel&filter[Carousel]=speakers&filter[posts_per_page]=-1"]];



NSURLResponse *requestResponse;
NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)requestResponse;
NSInteger statusCode = [HTTPResponse statusCode];

NSData *requestHandler = [[NSData alloc]init];
requestHandler = [NSURLConnection sendSynchronousRequest:request returningResponse:&requestResponse error:nil];

 NSLog(@"requestresponce: %@", requestHandler);

NSString *requestReply = [[NSString alloc] initWithBytes:[requestHandler bytes] length:[requestHandler length] encoding:NSASCIIStringEncoding];
NSLog(@"requestReply: %@", requestReply);

对我来说,请求处理程序的值就像“<>”一样,是什么问题。

1 个答案:

答案 0 :(得分:0)

获取并分析连接错误(如果有)和响应:

NSError *error;
NSData *requestHandler = [[NSData alloc]init];
requestHandler = [NSURLConnection sendSynchronousRequest:request returningResponse:&requestResponse error:&error];
NSLog(@"Connection error = %@", error);
NSLog(@"Response = %@", requestResponse);

如果没有这些信息,就无法确定问题出在哪里 - 可能是连接错误,网址错误,后端问题等等......