我在 ios 中创建了一个用户查询表单。我使用 php 作为服务器端。我在IOS中构造了如下查询字符串
http://www.mydomain.in/androidmail_enquiry.php?name=Vinoth Kumar&phone=04259280244&email=vinoth@ldomain.com&address=Coimbatore&comments=Sample Enquiry&mobile=xxxxxxxx
代码:
-(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);
}
但是当我通过使用 NSURLRequest 提交此错误时,在 didFailWithError 方法中出现无效 url(URL 形成错误)之类的错误。