两次请求?

时间:2013-05-03 08:07:10

标签: iphone xml-parsing http-post

我使用下面的代码向web服务发送请求并获得响应,但是在这里我一次两次得到请求,我不在哪里我错了,帮我从这个问题出来。提前致谢。

 NSString *poststr=[NSString stringWithFormat:@"&cname=%@&conname=%@&email=%@",companynametxt.text,contactnametxt.text,contactEmailtxt.text];
NSLog(@"poststr %@",poststr);


NSData *postData = [poststr dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];


NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString: @"web servicess"]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:postData];

[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
NSLog(@"DATA%@",theConnection);
[theConnection release];
NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

NSString *filenameStr=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];

NSLog(@"filenameStr %@",filenameStr);

1 个答案:

答案 0 :(得分:1)

您正在进行两次单独的通话

NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];

NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

使用其中任何一个而不是两个。

相关问题