gpt4 book ai didi

swift3 - Alamofire 发布请求问题

转载 作者:行者123 更新时间:2023-12-02 03:54:11 26 4
gpt4 key购买 nike

   let parameters = [
"checkout": [
"email": "john.smith@example.com",
"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 = "https://\(Key):\(Password)@sapphireonline-staging.myshopify.com/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)
}
}

为什么下面的代码会给我错误:

Alamofire 失败:- 错误 Domain=Alamofire.AFError Code=4 “由于错误,无法序列化 JSON:无法读取数据,因为它的格式不正确。”

最佳答案

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

关于swift3 - Alamofire 发布请求问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44277005/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com