私は、サーバーからJSONデータを送受信するためのURL接続を集中化する方法を検討しています。 POSTでは動作しますが、GETでは動作しません。私はGoogle App Engineサーバーを使用しています。私のコンピュータでは、POSTリクエストを処理して適切な結果を返す(適切にログする)が、GETメソッドでリクエストを試してみると、次のエラーが表示されます。NSURLConnectionが早く終了する
Error Domain=kCFErrorDomainCFNetwork Code=303 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error 303.)" UserInfo=0xd57e400 {NSErrorFailingURLKey=http://localhost:8080/api/login, NSErrorFailingURLStringKey=http://localhost:8080/api/login}
さらに、GAE開発サーバーは、サーバーがすべてのデータの送信を完了する前に、クライアントが接続を終了したことを示す「破損パイプ」エラーを表示します。
NSDictionary *response = [fetcher sendRequestToModule:@"login" ofType:@"GET" function:@"validate_email" params:dict];
を繰り返しますが、これは、POSTで動作しなくGET:
/* Connects to a given URL and sends JSON data via HTTP request and returns the result of the request as a dict */
- (id) sendRequestToModule:(NSString*) module ofType:(NSString*) type function:(NSString*) func params:(NSDictionary*) params {
NSString *str_params = [NSDictionary dictionaryWithObjectsAndKeys:func, @"function", params, @"params", nil];
NSString *str_url = [NSString stringWithFormat:@"%@%@", lds_url, module];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:str_url]];
NSData *data = [[NSString stringWithFormat:@"action=%@", [str_params JSONString]] dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPMethod:type];
[request setHTTPBody:data];
[request setValue:[NSString stringWithFormat:@"%d", [data length]] forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSError *error = nil;
NSURLResponse *response = nil;
NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(@"Error: %@", error);
NSLog(@"Result: %@", [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding]);
return [result objectFromJSONData];
}
サンプル呼び出しは次のようになります。
は、ここでの方法です。これをどうすれば解決できますか?
私は、おかげでそれを試してみますよ! – drodman