我的代码将数据发布到webservice时遇到问题。
有人可以请告诉我哪里出错了。
我需要将三个字段(doctorId-STRING,patientId.STRING,date-STRING)发布到此地址:
如何做到这一点?
NSString *post = [NSString stringWithFormat:@"&id_doktor=%@&id_pacijent=%@&datum=%@",@"iddoktora",@"idpacijenta",@"ovojedatum"];
NSData* postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
//You need to send the actual length of your data. Calculate the length of the post string.
NSString *postLength = [NSString stringWithFormat:@”%d”,[postData length]];
//Create URLRequest object and initialize it.
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
//Set the Url for which your going to send the data to that request
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.walter-dev.com/doctor/public/setTermin"]]];
//set HTTP method (POST)
[request setHTTPMethod:@"POST"];
//Set header field with lenght of the post data
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
//I dont understand this line of code
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
//Set httpbody of the urlrequest with string "post"
[request setHTTPBody:postData];
//Initialize object with urlRequest
NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
if(conn)
{
NSLog(@"Konekcija prema serveru je uspjela");
}
else
{
NSLog(@"NIJE USPJELA ");
}