I am new to iPhone application development and also this stackoverflow,if I made any mistakes sorry. I have some of the questions
1)我是否需要在我的应用程序中安装任何其他外部框架。我正在使用SDK Simulator 4.2
2)我已经浏览了这里发布的一些材料,我发现了一些代码,我做了一些修改以适应我的应用程序当我请求一个URL时,它返回给我NULL。
3)我的任务是将三个参数发送到数据库中。
NSString *post =[NSString stringWithFormat:@"?FirstName=%@?Surname=%@?IDNumber=%@?DOB=%@",namestring,surnamestring,cidstring,dobstring];
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSLog(@"Post Length:",[postData length]);
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://www.esoft.co.za/MDS/Service1.asmx?op=InsertSuppliers"]];
[request setHTTPMethod:@"GET"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSLog(@"response data is: %@",[responseData length] );
NSString *data = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"Data: %@",data);
感谢Advance Guys ...请提供任何示例代码或材料..
答案 0 :(得分:0)
我认为这是因为您尝试发送无效请求。只是尝试检查并记录错误消息,看看有什么问题。
您要做的是通过GET请求发送POST数据,这无论如何都是错误的。我也不确定那些“Post”数据格式,但是当你检查错误信息时你会发现错误。
NSLog(@"Request failed with error: %@", [err localizedDescription]);
最好的