サーバーに HTTP リクエストを送信し、データを取得したいと考えています。
これが私のコードです:
NSString *post = @"mode=1";
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSURL *url = [NSURL URLWithString:[@"http://example.com" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
//if i will give the url http://example.com?mode=1 it works
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody:postData];`
サーバーが mode=1 パラメーターを取る場合、SQL クエリを作成し、いくつかのデータを返します。
この方法では機能しませんsetHTTPBody
。
パラメータmode=1
をURLに直接配置すると、機能します。
どこが間違っているか教えてもらえますか? さらに説明が必要な場合はお知らせください。