我正在从客户端对服务器进行异步调用,并在服务器上打印数据。但是我在客户那里得到的回应是空的
我的回复检索部分如下:-
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[receivedData setLength:0];
NSLog(@"connection did receive response");
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
// Append the new data to receivedData.
// receivedData is an instance variable declared elsewhere
if(!receivedData)
{
receivedData = [NSMutableData data];
}
[receivedData appendData:data];
NSLog(@"connection did receive data");
}
- (void)connection:(NSURLConnection *)connection
didFailWithError:(NSError *)error
{
// inform the user
NSLog(@"Connection failed! Error - %@ %@",
[error localizedDescription],
[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// receivedData is declared as a method instance elsewhere
NSString *responseFromServer = [[NSString alloc]initWithData:receivedData encoding:NSUTF8StringEncoding];
NSLog(@"connection did finish load");
NSLog(@"response from the server=%@", responseFromServer);
}
所以'responseFromServer'的值是空的。
谁能告诉我我哪里出错了。提前致谢。