字符串json的post发送方式

今天上面给了个url:https://apit3.51mch.com/api/PatInfo/GetPatInfo?jsonStr={"CardNo":"135403000800151","HashKey":"63d0ab17-8877-44ba-b17d-e6ad14032516"}叫我发post请求。我一脸蒙蔽。

反复研究后原来,key是jsonStr value是后面的{"CardNo":"135403000800151","HashKey":"63d0ab17-8877-44ba-b17d-e6ad14032516"}

具体发送代码:

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 后面省略}

还是小朋友帮我想出来- -,哎  做个记录。 这里重点提下encoding,这个编码格式是URLEncodedInURL.这个就是我要写这篇东西的关键。。我去查了相关资料,我觉得这里还是用英文复制粘粘上来比较准确。

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就是创建要被设置为或附加到任何现有的网址查询的查询字符串。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 什么时候开始,貌似我对所谓的终生大事不着急了,现在觉得自己单身的生活反而更有激情,总觉得自己有做不完的事情...
    红柚子阅读 325评论 0 0
  • 4.6 读完第一章到第五章的随手记 一开始读这本书觉得有些艰涩和枯燥,但越读越明白作者在说什么,也有了更多Aha ...
    YinNan阅读 400评论 0 2
  • 四种引用类型主要是为了使得jvm的垃圾回收更加可控 强引用 如果对象存在一个强引用则不能被回收,及时报OOM 弱引...
    贫僧吃猪蹄阅读 237评论 0 0
  • 前些天,作为家长参加了孩子小学的首次家长会。会上的宣讲老师提到,多年前流行“学会数理化,走遍天下都不怕”。现如今,...
    伯涵子弟阅读 884评论 0 5
  • 文/木鱼书缃 我们都特别想在别人的心里获得满分,可事实总是事与愿违。 小时候我很丑,虽然现在也很丑,可是小时候更丑...
    木鱼书缃阅读 971评论 6 8

友情链接更多精彩内容