I have created one user enquiry form in ios. I'm using php as a server side. I constructed query string like bellow in IOS
http://www.mydomain.in/androidmail_enquiry.php?name=Vinoth Kumar&phone=04259280244&[email protected]&address=Coimbatore&comments=Sample Enquiry&mobile=xxxxxxxx
Code:
-(void)sendEnquiryDetails
{
cmttextview.text = @"Sample Enquiry";
NSString *siteurl = @"http://www.mydomain.in/androidmail_enquiry.php?";
NSString *name = txtName.text;
NSString *phone = txtPhone.text;
NSString *email = txtEmail.text;
NSString *address = txtAddress.text;
NSString *comments = cmttextview.text;
NSString *mobile = txtMobile.text;
NSString *enquiryurl = [NSString stringWithFormat:@"%@name=%@&phone=%@&email=%@&address=%@&comments=%@&mobile=%@",siteurl,name,phone,email,address,comments,mobile];
NSLog(enquiryurl);
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:enquiryurl]];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
//NSLog(@"didReceiveResponse");
[self.responseData setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[self.responseData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"%@",[NSString stringWithFormat :@"didfailwitherror: %@", [error description]]);
}
-(void)connectionDidFinishLoading: (NSURLConnection *)connection{
NSLog(@"Success Code:%@",self.responseData);
}
But when i submit this by using NSURLRequest getting error like invalid url(URL Forming error) in didFailWithError method.
Make sure You have added stringByAddingPercentEscapesUsingEncoding , because in your url there is space in name , so in browser it is replaced with %20 you have to add programmatically in code,
Try this
-(void)sendEnquiryDetails
{
cmttextview.text = @"Sample Enquiry";
NSString *siteurl = @"http://www.mydomain.in/androidmail_enquiry.php?";
NSString *name = txtName.text;
NSString *phone = txtPhone.text;
NSString *email = txtEmail.text;
NSString *address = txtAddress.text;
NSString *comments = cmttextview.text;
NSString *mobile = txtMobile.text;
NSString *enquiryurl = [NSString stringWithFormat:@"%@name=%@&phone=%@&email=%@&address=%@&comments=%@&mobile=%@",siteurl,name,phone,email,address,comments,mobile];
NSLog(enquiryurl);
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[enquiryurl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With