当我发布像
这样的简单JSON时{\" body \":\" test \"," subject \":\" test \&#34 ;}
它工作正常,但当我发布数据时(如下)
{" body":" hello
名字Paul A Alabisi姓氏客户ID 31877 Serail Key 2512948ead29a82d"," subject":" hi"}
这是错误
{"错误":{"错误":[{ "域":"全球", "原因":" parseError", "消息":"解析错误" },"代码":400,"消息":"解析错误" }}
这是我的Objective C代码:
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:URL]];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
//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");
}