加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swfit post json and header

发布时间:2020-12-15 20:04:56 所属栏目:百科 来源:网络整理
导读:?{ ????????var??path?=?" http://wxxxxxxxcom/v1/app/users/login" ????????var?params:?NSMutableDictionary?=?NSMutableDictionary() ????????params["mobile_phone"]?=?"18319037770295" ????????params["password"]?=?"123456" ???????? ? ? ?? ???????
?{
????????var??path?=?"

http://wxxxxxxxcom/v1/app/users/login"
????????var?params:?NSMutableDictionary?=?NSMutableDictionary()
????????params["mobile_phone"]?=?"18319037770295"
????????params["password"]?=?"123456"
????????
? ? ??
????????//?1.?URL
????????var?url:?NSURL?=?NSURL(string:?path)!
????????
????????//?2.?请求(可以改的请求)
????????var?request:?NSMutableURLRequest?=?NSMutableURLRequest(URL:?url)
????????//???POST
????????//?默认就是GET请求
????????request.HTTPMethod?=?"POST"
????????
????????//???数据体
????????var?jsonData:NSData??=?nil
????????do?{
????????????jsonData??=?try?NSJSONSerialization.dataWithJSONObject(params,?options:?NSJSONWritingOptions.PrettyPrinted)
????????}?catch?{
????????????
????????}
????????//?将字符串转换成数据
????????request.HTTPBody?=?jsonData
????????
???????? request.setValue("5d5ec577-8cd1-4738-9f88-c97d222716a5",?forHTTPHeaderField:?"App-Token")
???????? NSURLConnection.sendAsynchronousRequest(request,?queue:?NSOperationQueue())?{?(res,?data,?error)?in ???????????? ? ? ? ? ? ? ?let??str?=?NSString(data:?data!,?encoding:?NSUTF8StringEncoding) ????????????????print(str) ???????????? ????????} ????}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读