我想將字符串數據發佈到API,我嘗試使用以下代碼將其發送到服務器。我使用郵遞員檢查了那裏的api,它沒有將字符串數據傳入服務器。我不知道這是什麼問題,需要幫助。如何將字符串數據發佈到API
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:reqURLStr]];
[request setHTTPMethod:@"POST"];
**//Pass The String to server**
NSString *userUpdate =[NSString stringWithFormat:@"service_type=%@&ParcelSize=%@&ReceiverName=%@&MobileNumber=%@&Email=%@&DropOffHub=%@&PickupHub=%@" ,serviceType,pSize,rName,rMobile,rEmail,dropHubID,pickHubID];
NSData *data1 = [userUpdate dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:data1];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:[data makeRestAPICall:reqURLStr] forHTTPHeaderField:@"Authorization"];
NSError *err;
NSURLResponse *response;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSString *resSrt = [[NSString alloc]initWithData:responseData encoding:NSASCIIStringEncoding];
NSLog(@"got response==%@", resSrt);
if(resSrt)
{
NSLog(@"got response");
}
else
{
NSLog(@"fail to connect");
}
return resSrt;
你從響應得到了什麼錯誤? –
{狀態碼:400,標題「Cache-Control」=「no-cache」; 「Content-Length」= 0; 日期=「星期六,2017年6月3日06:37:33 GMT」; Expires =「-1」; Pragma =「no-cache」; Server =「Microsoft-IIS/7.5」; 「X-AspNet-Version」=「4.0.30319」; 「X-Powered-By」=「ASP.NET」; } – Nurburgring
我「po迴應」,它告訴我這 – Nurburgring