クライアントからサーバーへの非同期呼び出しを行い、サーバーにデータを出力しています。しかし、クライアントで得た応答はnullとして来ています
私の応答検索部分は次のとおりです:-
- (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」の値は null になります。
どこが間違っているのか誰にも教えてもらえますか。前もって感謝します。