我用ASIHTTPRequest
工作:发送HTTP请求并解析JSON响应
NSURL *url = [NSURL URLWithString:@"http://data.mywebsite/api/views/INLINE/rows.json?method=index"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
request.requestMethod = @"POST";
[request addRequestHeader:@"Content-Type" value:@"application/json"];
[request appendPostData:[json dataUsingEncoding:NSUTF8StringEncoding]];
[request setDelegate:self];
[request setCompletionBlock:^{
NSString *responseString = [request responseString];
NSLog(@"Response: %@", responseString);
}];
[request setFailedBlock:^{
NSError *error = [request error];
NSLog(@"Error: %@", error.localizedDescription);
}];
[request startAsynchronous];
由于ASIHTTPRequest不再维持,我搬到AFNetworking
API。 但是,当从一个逻辑移动到另一个不同时,我有点困惑,我想知道如何通过AFNetworking
传递相同的请求。
Thanx提前。
为什么不使用更新NSURLConnection的方法呢? – bandejapaisa 2012-03-17 21:39:37
我需要使用'AFNetworking' API。 – Luca 2012-03-17 22:04:29
[AFNetworking Post Request]的可能重复(http://stackoverflow.com/questions/7623275/afnetworking-post-request) – JosephH 2012-03-18 06:53:55