我想使用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. 如何使用node.js http-proxy在計算機中記錄HTTP通信?
- 4. 在iPhone上註冊短信通知
- 5. 使用CoreTelephony在iPhone上發送彩信
- 6. iPhone到iPhone通信
- 7. iPhone到iPhone通信
- 8. iPhone應用程序崩潰在http post上使用asi-http-request
- 9. 如何通過iphone上的API獲取CPU利用率信息?
- 10. 如何在iPhone上通過GPS獲取「標題」信息WebApp
- 11. 如何在iphone上使用phonegap發送短信?
- 12. 如何在iphone上存儲信用卡信息?
- 13. Android HTTP通信:
- 14. 如何通過設計使用SWFUPLOAD for iPhone Http服務器
- 15. 如何使用HTTP POST方法iphone
- 16. 使用jsp通過HTTP發送短信
- 17. 使用.htaccess強制HTTP通信到HTTPS
- 18. 如何使用HTTP處理程序進行client2client通信?
- 19. 使用iPhone上的CONNECT方法通過SSL實現HTTP代理
- 20. 使用iPhone接收短信通知
- 21. JSON通過HTTP iPhone
- 22. 如何使用「iphone套接字」編程通信協議?
- 23. 如何從iPhone上傳使用HTTP POST的音頻文件?
- 24. iPhone應用程序通信
- 25. 用libusb與iPhone通信
- 26. iPhone如何與電腦通信?
- 27. OS X上的HTTP通信監視
- 28. 端口80上的HTTP通信
- 29. 如何通過編程在iPhone上使用Twitvid在Twitter上上傳視頻
- 30. 如何在Xcode上使用HTTP POST
當我學習時,很高興知道如何使用特定代碼完成工作。之後,我可能希望使用開源代碼簡化工作。不管怎麼說,還是要謝謝你。 – 2009-02-27 08:03:16