gpt4 book ai didi

iphone - 收到两次请求?

转载 作者:行者123 更新时间:2023-12-03 19:01:02 27 4
gpt4 key购买 nike

我使用下面的代码向网络服务发送请求并获取响应,但在这里我一次收到两次请求,我不知道我在哪里犯了错误,请帮助我解决这个问题。提前致谢。

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

最佳答案

您正在调用两个单独的电话

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

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

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

关于iphone - 收到两次请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16354253/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com