【发布时间】:2013-12-05 11:00:17
【问题描述】:
我想将我的 UITextfields 数据发送到服务器。
我想发布数据,但服务器向我显示错误消息。
请检查我的代码:
...
NSURL *url=[NSURL URLWithString:@"http://projectsatseoxperts.net.au/fishing/api/postRegister.php"];
NSString *post =[[NSString alloc] initWithFormat:@"FirstName=%@&LastName=%@userName=%@&Email=%@Phone=%@&Address=%@Password=%@&ConfirmPassword=%@",
txt_firstname.text,txt_lastname.text,txt_username.text,txt_email.text,txt_phone.text,txt_address.text,txt_password.text,txt_confirmpassword.text];
NSLog(@"Post is: %@",post);
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSLog(@"postData is: %@",postData);
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSLog(@"postLength is: %@",postLength);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
//[request setValue:@"http://projectsatseoxperts.net.au/fishing/api/postRegister.php" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSLog(@"request is: %@", [request allHTTPHeaderFields]);
NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(@"urlData is: %@",urlData);
NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"%@",data);
}
发布详细信息后,值将出现在这里 - http://projectsatseoxperts.net.au/fishing/api/register.php
非常欢迎任何想法或建议。
【问题讨论】:
-
你从服务器得到什么错误?
-
"错误" , NSLog(@"%@",data);
-
我发布的数据对吗?有什么我没见过的东西吗?
-
看起来不错。我们需要了解您实际收到了哪些错误消息才能为您提供帮助。
-
我建议您联系 API 开发人员并告知他们返回状态代码 200 和“错误”正文既无效而且无益,他们应该考虑提供更详细的错误消息和适当的 HTTP 状态代码。
标签: ios iphone objective-c post http-post