Alamofire发布请求问题

编程入门 行业动态 更新时间:2024-10-25 14:32:12
本文介绍了Alamofire发布请求问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 let parameters = [ "checkout": [ "email": "john.smith@example", "line_items": [ "variant_id": 31342168513, "quantity": 1 ], "shipping_address": [ "first_name": "John", "last_name": "Smith", "address1": "126 York St.", "city": "Ottawa", "province_code": "ON", "country_code": "CA", "phone": "(123)456-7890", "zip": "K1N 5T5" ] ] ] let urlString = "\(Key):\(Password)@sapphireonline-staging.myshopify/admin/checkouts.json" let headers: HTTPHeaders = [ "X-Shopify-Storefront-Access-Token": "5681ded39ead3fa6f4594ad0981367", "Content-Type": "application/json" ] Alamofire.request(urlString, method:.post, parameters: parameters,encoding: JSONEncoding.default, headers:headers).responseJSON { response in switch response.result { case .success: print("\n\n Alamofire Response . resposne :- ", response) case .failure(let error): print("\n\n Alamofire Failure :- ",error as NSError) } }

以下代码为什么给我错误:

Why does the following code give me the error:

Alamofire失败:-错误Domain = Alamofire.AFError代码= 4由于错误,JSON无法序列化:由于数据不在其中,因此无法读取数据正确的格式。

Alamofire Failure :- Error Domain=Alamofire.AFError Code=4 "JSON could not be serialized because of error: The data couldn’t be read because it isn’t in the correct format."

推荐答案

服务器的响应不是JSON。也许您收到错误响应。建议您检查一下响应错误代码或使用curl尝试相同的请求。

The response from the server is not JSON. Maybe you got an error response. I suggest you check the response error code or try the same request using curl.

更多推荐

Alamofire发布请求问题

本文发布于:2023-11-26 03:29:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632454.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Alamofire

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!