0

Google エンドポイント (Python) を使用してメール ユーティリティを作成しました。問題は、データを POST できないことです。エラーが発生しています。

{ "error": { "errors": [ { "domain": "global", "reason": "parseError", "message": "この API はフォーム エンコードされた入力の解析をサポートしていません。" } ], "code": 400, "message": "この API は、フォーム エンコードされた入力の解析をサポートしていません。" } }

私がObjective-Cでやっていることを以下に示します

//Here my URL
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:URL]];


//create the Method "GET" or "POST"
[request setHTTPMethod:@"POST"];

//Pass The String to server
NSString *dataPost = @"{\"body\": \"email body\",\"subject\": \"email subject\"}";

//Check The Value what we passed
NSLog(@"the data Details is =%@", dataPost);

//Convert the String to Data
NSData *data1 = [dataPost dataUsingEncoding:NSUTF8StringEncoding];

//Apply the data to the body
[request setHTTPBody:data1];

//Create the response and Error
NSError *err;
NSURLResponse *response;

NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];

NSString *resSrt = [[NSString alloc]initWithData:responseData encoding:NSASCIIStringEncoding];

//This is for Response
NSLog(@"got response==%@", resSrt);
if(resSrt)
{
    NSLog(@"got response");
    /* ViewController *view =[[ViewController alloc]initWithNibName:@"ViewController" bundle:NULL];
     [self presentViewController:view animated:YES completion:nil];*/
}
else
{
    NSLog(@"faield to connect");
}
4

1 に答える 1

1

参照してください: NSURLRequest を使用して Http リクエストで json データを送信する方法

基本的に、「Content-Type」ヘッダーを設定して、受信エンドポイントがフォーム エンコードされているとは見なさず (デフォルト)、代わりに JSON として認識する必要があります。

[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
于 2015-09-10T17:09:15.897 に答える