今天上面給了個url:https://apit3.51mch.com/api/PatInfo/GetPatInfo?jsonStr={"CardNo":"135403000800151","HashKey":"63d0ab17-8877-44ba-b17d-e6ad14032516"}叫我發(fā)post請求。我一臉蒙蔽。
反復(fù)研究后原來,key是jsonStr value是后面的{"CardNo":"135403000800151","HashKey":"63d0ab17-8877-44ba-b17d-e6ad14032516"}
具體發(fā)送代碼:
let param = ["jsonStr":"{\"CardNo\":\"135403000800151\",\"HashKey\":\"63d0ab17-8877-44ba-b17d-e6ad14032516\"}"]
Alamofire.request(.POST, "https://apit3.51mch.com/api/PatInfo/GetPatInfo", parameters: param, encoding: .URLEncodedInURL, headers: nil).responseJSON { (resquest, response, result) in 后面省略}
還是小朋友幫我想出來- -,哎 ?做個記錄。 這里重點(diǎn)提下encoding,這個編碼格式是URLEncodedInURL.這個就是我要寫這篇東西的關(guān)鍵。。我去查了相關(guān)資料,我覺得這里還是用英文復(fù)制粘粘上來比較準(zhǔn)確。
Used to specify the way in which a set of parameters are applied to a URL request.
URL: Creates a query string to be set as or appended to any existing URL query forGET,HEAD, andDELETErequests, or set as the body for requests with any other HTTP method. TheContent-TypeHTTP header field of an encoded request with HTTP body is set toapplication/x-www-form-urlencoded; charset=utf-8. Since there is no published specification for how to encode collection types, the convention of appending[]to the key for array values (foo[]=1&foo[]=2), and appending the key surrounded by square brackets for nested dictionary values (foo[bar]=baz).
URLEncodedInURL: Creates query string to be set as or appended to any existing URL query. Uses the same implementation as the.URLcase, but always applies the encoded result to the URL.
JSON: UsesNSJSONSerializationto create a JSON representation of the parameters object, which is set as the body of the request. TheContent-TypeHTTP header field of an encoded request is set toapplication/json.
PropertyList: UsesNSPropertyListSerializationto create a plist representation of the parameters object, according to the associated format and write options values, which is set as the body of the request. TheContent-TypeHTTP header field of an encoded request is set toapplication/x-plist.
Custom: Uses the associated closure value to construct a new request given an existing request and parameters.
簡單來說URLEncodedInURL就是創(chuàng)建要被設(shè)置為或附加到任何現(xiàn)有的網(wǎng)址查詢的查詢字符串。