2011-06-01 154 views
0
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模拟器4.2如何从我的iPhone应用程序访问SOAP Web服务

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); 

在此先感谢家伙...请给我提供任何示例代码或材料..

回答

0

我想这是因为你想发送无效的请求。试着检查并记录错误信息,看看有什么不对。

你要做的是通过GET请求发送POST数据,这是错误的。我也不确定那些“Post”数据格式,但是当你检查错误信息时,你会发现什么是错误的。

NSLog(@"Request failed with error: %@", [err localizedDescription]); 

最好

+0

我更新了我的代码与所有的POST请求 – user603644 2011-06-03 00:38:44

相关问题