我在 Google Endpoints (Python) 的帮助下创建了一个电子邮件实用程序。问题是我无法向其发布数据。我收到一个错误。
{ "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");
}