我想使用HTTP连接到服务器,向它发送一个字符串并从服务器接收响应字符串。有关如何通过url连接到服务器的任何想法,发送和接收来自它的消息?如何在iPhone上使用HTTP通信?
0
A
回答
4
// create the request
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"]
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) {
// Create the NSMutableData that will hold
// the received data
// receivedData is declared as a method instance elsewhere
receivedData=[[NSMutableData data] retain];
} else {
// inform the user that the download could not be made
}
1
您可以连接到服务器,发送字符串,并使用NSMutableURLRequest
和NSURLConnection
类接收响应。一个好的开始是Introduction to the URL Loading System。
4
我建议使用All-Seeing Interactive的优秀ASIHTTPRequest源代码:http://allseeing-i.com/ASIHTTPRequest。我正在这样做,所以有几个已发布的iPhone应用程序,所以你可以确信代码非常稳定。
这是一个围绕CFNetwork API的包装,它使与Web服务器通信更加单调乏味。它用Objective-C编写,适用于Mac OS X和iPhone应用程序。
它适用于执行基本HTTP请求并与基于REST的服务(GET/POST/PUT/DELETE)交互。 ASIFormDataRequest子类可以使用multipart/form-data轻松提交POST数据和文件。
相关问题
- 1. 如何比HTTP通信更好地使用TCP通信?
- 2. 在iPhone上注册短信通知
- 3. 使用CoreTelephony在iPhone上发送彩信
- 4. iPhone到iPhone通信
- 5. iPhone到iPhone通信
- 6. 如何通过iphone上的API获取CPU利用率信息?
- 7. 如何在iPhone上通过GPS获取“标题”信息WebApp
- 8. Android HTTP通信:
- 9. 如何通过设计使用SWFUPLOAD for iPhone Http服务器
- 10. 如何使用HTTP处理程序进行client2client通信?
- 11. 如何使用HTTP POST方法iphone
- 12. 使用iPhone上的CONNECT方法通过SSL实现HTTP代理
- 13. 如何使用“iphone套接字”编程通信协议?
- 14. 端口80上的HTTP通信
- 15. OS X上的HTTP通信监视
- 16. 如何从iPhone上传使用HTTP POST的音频文件?
- 17. 用libusb与iPhone通信
- 18. iPhone如何与电脑通信?
- 19. 如何在Android上使用HTTP GET?
- 20. 如何使用XML在网络上进行通信?
- 21. 如何在Android上使用WebRTC进行实时通信?
- 22. 如何在iPhone上使用iPhone上的多个同伴与GameKit?
- 23. 如何在iPhone上使用Qt库
- 24. 如何在iPhone上使用Base64编码
- 25. 如何在iPhone上使用Tapku库?
- 26. 如何在iPhone上使用SSH
- 27. 如何在iphone上使用glib?
- 28. 如何在iPhone上使用windowScriptObject?
- 29. 如何在iPhone上使用python api?
- 30. 如何在iPhone上使用Google地球?
当我学习时,很高兴知道如何使用特定代码完成工作。之后,我可能希望使用开源代码简化工作。不管怎么说,还是要谢谢你。 – 2009-02-27 08:03:16