字符串json的post發(fā)送方式

今天上面給了個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)址查詢的查詢字符串。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 什么時候開始,貌似我對所謂的終生大事不著急了,現(xiàn)在覺得自己單身的生活反而更有激情,總覺得自己有做不完的事情...
    紅柚子閱讀 329評論 0 0
  • 4.6 讀完第一章到第五章的隨手記 一開始讀這本書覺得有些艱澀和枯燥,但越讀越明白作者在說什么,也有了更多Aha ...
    YinNan閱讀 406評論 0 2
  • 四種引用類型主要是為了使得jvm的垃圾回收更加可控 強(qiáng)引用 如果對象存在一個強(qiáng)引用則不能被回收,及時報OOM 弱引...
    貧僧吃豬蹄閱讀 239評論 0 0
  • 前些天,作為家長參加了孩子小學(xué)的首次家長會。會上的宣講老師提到,多年前流行“學(xué)會數(shù)理化,走遍天下都不怕”?,F(xiàn)如今,...
    伯涵子弟閱讀 899評論 0 5
  • 文/木魚書緗 我們都特別想在別人的心里獲得滿分,可事實(shí)總是事與愿違。 小時候我很丑,雖然現(xiàn)在也很丑,可是小時候更丑...
    木魚書緗閱讀 974評論 6 8

友情鏈接更多精彩內(nèi)容