ios網路程式設計01

2021-07-05 06:00:28 字數 1953 閱讀 6616

在ios下進行網路程式設計主要分為以下三步:

1.客戶端向伺服器傳送請求

客戶端和伺服器請求的方式主要有兩種:get和post

get請求:將資訊直接拼接在url的後面。(在真正開發中用到的比較多)

post請求:將一些比較重要的資訊轉化成二進位製流。(在真正開發中,post請求常常用於驗證使用者名稱,密碼是否是否正確,給伺服器上傳資料等)

注意:1.不管是get請求還是post請求都是有後台決定的,程式設計師可以通過介面文件知道當前的請求方式。

2.請求方式還有delete,put等方式。除了get請求可以使用nsurlrequest之外,其他的請求必須使用nsurlmutablerequest,明確指定當前的httpmethod是什麼請求。

2.和伺服器建立連線

3.伺服器做出響應

[nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue currentqueue] completionhandler:^(nsurlresponse *response, nsdata *data, nserror *connectionerror) ];//get方式

nsurl *url1 = [nsurl urlwithstring:@"hahahaha"];

[nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue currentqueue] completionhandler:^(nsurlresponse *response, nsdata *data, nserror *connectionerror) ];//post方式

nsstring *contentstr = [nsstring stringwithcontentsofurl:urll encoding:nsutf8stringencoding error:nil];

// 3.轉化為xmldocument(當執行完這一步時,整個文件已經被解析完畢,並且轉化為xmldocument進行儲存。同時文件對應的樹形結構也已經清晰明了了)

gdataxmldocument *document = [[gdataxmldocument alloc]initwithxmlstring:contentstr options:0 error:nil];

nsarray *node = [document nodesforxpath:@"// /picurl" error:nil];

nslog(@"%@",node[0]);

uiimageview *aaa =[[uiimageview alloc]initwithimage:[uiimage imagewithdata:[nsdata datawithcontentsofurl:[nsurl urlwithstring:[node[0] stringvalue]]]]];//xml解析

網路程式設計 01

一 tcp ip 1 tcp ip協議的理解 網路傳輸協議 tcp 基於位元組流的傳輸層 通訊協議,主要用於發現傳輸中的錯誤,要去重新發 ip 網路層協議。2 名詞的理解 ip 網路層的唯一識別id。tcp 面向連線層的協議,需要三次握手才能建立通訊。分別是 客戶端 向伺服器傳送 同步訊號,即告訴伺...

網路程式設計 01

網路程式設計 網路目的 資料的傳輸 網路資料傳輸是乙個複雜的過程 iso 國際標準化組織 osi 七層模型 網路通訊標準化流程 應用層 提供使用者服務,具體內容由特定程式規定 表示層 資料的壓縮優化 會話層 建立應用連線,選擇傳輸層服務 傳輸層 提供不同的傳輸服務,流量控制 網路層 路由選擇,網路互...

網路程式設計01

軟體架構的兩種方式 c s架構 client 客戶端 基於網路 server 服務端 b s架構 browser 客戶端 基於網路 server 服務端 ps 1.服務端和客戶端都必須有唯一的位址,但是服務端的位址必須是繫結的 2.服務端必須要24小時對外提供服務 3.服務端要能支援併發 網路程式設...