现在我想得到回复正文。我是IOS开发人员中的新人。我只知道我可以使用response.statusCode来获取httpstatuscode,例如400,500等等。但如何获得反应机构。也许allheaderFileds或数据或error.Description?
答案 0 :(得分:1)
有关详细信息,请访问:URL Loading System Programming Guide
您需要一个作为NSURLConnection
代表的对象。你需要有一个receivedData
成员变量,你需要实现委托方法:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[receivedData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
// Append the new data to receivedData.
// receivedData is an instance variable declared elsewhere.
[receivedData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// do something with the data
// release the connection, and the data object
[connection release];
[receivedData release];
}