iPhoneからWebサービス(SOAP上のRESTレイヤー)にPOSTリクエストを送信しています。iPhoneデバイスとシミュレータの両方でテストしているエラー408リクエストタイムアウトが発生します。シミュレーターでテストしたところ、最初にブラウザーからWebサーバーにアクセスし、次にシミュレーターを実行すると、問題が解決し、通信が機能することに気付きました。動作はこの質問に非常に似ていますHTTP、408リクエストのタイムアウト POSTリクエストを作成するために使用しているコードは次のとおりです。誰かがこの行動に出くわし、解決策を見つけましたか?
NSString * urlString = [NSString stringWithFormat:@"%@%@", kBaseURL,method];
NSURL * myURL = [NSURL URLWithString:urlString];
NSLog(@"URL %@", myURL);
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:myURL];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[theRequest setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
[theRequest setTimeoutInterval:60]; // leave at default 60 secs
NSLog(@"Post Body: %@",body);
NSURLConnection *theConnection = [[NSURLConnection alloc]
initWithRequest:theRequest
delegate:self];
if( theConnection ) {
if (webData){
[webData release];
}
webData = [[NSMutableData data] retain];
NSLog(@"connection set up");
}
else {
NSLog(@"theConnection is NULL");
}
self.mainConnection=theConnection;
[theConnection release];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;