I want to send my deviceid device type and phone number to server when I click on a button. I wrote my code here but it's not functioning properly. I dont know whats the problem is.
- (IBAction)sendPostData:(id)sender {
NSString *post=[NSString stringWithFormat:@"&DeviceId=mac123&DeviceType=ios&Phone=%@",phoneNumberTxt.text];
NSData *postData=[post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postLength =[NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
NSMutableURLRequest *request=[[NSMutableURLRequest alloc]init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://192.168.1.27:8080/MeetingPoint/api/Register"]]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
[request setHTTPBody:postData];
NSURLConnection *connection=[[NSURLConnection alloc]initWithRequest:request delegate:self];
[connection start];
if (connection) {
NSMutableData *mydata=[[NSMutableData alloc]init];
mydata=[NSMutableData data];
NSLog(@"data is :%@",mydata);
}
}
Try and use this:
Thanks.