我试着用Swift3和Alamofire发布一个JSON,它在PostmanPostman screen shot
但在代码中,响应是HTML字符串,这意味着服务器中出现异常
我尝试将编码从JsonEncoding.default
更改为URLEncoding.default
,效果很好,但3天后运行应用程序时出现了相同的错误
let url = "http://mattam.net/mobileapp/addOrder"
let par:[String:Any] = ["order_restaurant":8,
"order_type":1,
"order_address":1,
"order_within":"45 mins",
"order_exacttime":"09:00 pm",
"order_total":300,
"order_fees":30,
"order_gtotal":330,
"order_user":38,
"pquantity[10]":3,
"pquantity[9]":1,
"poption[9]":238,
"pextra[10]":"80,81"]
print(par)
Alamofire.request(url, method: .post, parameters: par, encoding: URLEncoding.default).responseJSON{
r in
if r.result.isSuccess{print("------i______i-----")}
print(r)
if let result = r.result.value as? NSDictionary{
print(result)}
}
在邮递员的批量编辑中
order_restaurant:8
order_type:1
order_address:1
order_within:45 mins
order_exacttime:09:00 pm
order_total:300
order_fees:30
order_gtotal:330
order_user:38
pquantity[10]:3
pquantity[9]:1
poption[9]:238
pextra[10]:80,81
url是“let url=”http://mattam.net/mobileapp/addOrder“”
最佳答案
你的问题是你在应用程序中使用http
而不是https
。
屏幕截图使用https
,而发布的url(从代码中复制)使用http
。