【问题标题】:Get a request twice?两次收到请求?
【发布时间】:2013-04-27 13:58:18
【问题描述】:

我正在使用以下代码向 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);

【问题讨论】:

    标签: iphone xml-parsing http-post


    【解决方案1】:

    您正在拨打两个单独的电话

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

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

    使用其中之一,而不是同时使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-01
      • 2014-09-19
      • 2019-05-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多