
Nsstring *post = [Nsstring stringWithFormat:@"http://blahblah.com/suggest.PHP?s=%@&n=%@&e=%@",suggestion,name,email]; // Create the request. NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:post] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; // create the connection with the request // and start loading the data NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; if (theConnection) { NSLog(@"Connection estabListed successfully"); } else { NSLog(@"Connection Failed."); } 我检查了所有的字符串并用等编码所有空格.任何人都可以看到任何明显的原因,为什么我的脚本将无法正常工作?
在不打开Safari的情况下,从我的应用程序发出http请求的最简单方法是什么?
解决方法 您的问题是您正在创建连接,但不发送实际的“连接”请求.代替NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
尝试使用这段代码:
NSURLResponse* response = nil;NSData* data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil]
这是一个快速而又脏的解决方案,但请记住,当此连接正在进行时,您的UI线程似乎将被冻结.解决它的方法是使用异步连接方法,这比上面的方法复杂一点.在网上搜索NSURLConnection发送异步请求 – 答案就在那里.
@H_502_40@ 总结以上是内存溢出为你收集整理的使用IOS 5发出HTTP GET请求的最简单方法是什么?全部内容,希望文章能够帮你解决使用IOS 5发出HTTP GET请求的最简单方法是什么?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)