【问题标题】:How to call a post API which has parameters like get api in Alamofire Swift?如何在 Alamofire Swift 中调用具有 get api 等参数的 post API?
【发布时间】:2019-10-18 18:22:35
【问题描述】:

我检查了许多堆栈溢出问题,但无法找到以下问题的答案。如何使用 Alamofire Swift 请求具有 get api 等参数的 post api?

请求:

http://dev.practice.com/api/v1/test/apply?id=51&social_id=2

主体:

"url": https://www.social.com/some_image_url

我尝试了以下方法,但它不起作用:

let urlString = "http://dev.practice.com/api/v1/test/apply?id=51&social_id=2"

Alamofire.request(urlString, method: .post, parameters: ["url": "https://www.social.com/some_image_url"],encoding: JSONEncoding.httpBody, headers: header).responseJSON {  
response in
  switch response.result {
                case .success:
                    print(response)

                    break
                case .failure(let error):

                    print(error)
                }
}

【问题讨论】:

  • 明确地说,您是在询问 URL 中的 URL 编码参数和同一请求中的 JSON 正文吗?

标签: swift http-post alamofire alamofire-request


【解决方案1】:

答案是:

我们必须将 get api 类参数请求为queryString,并将正文参数作为httpBody 与请求一起发送。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-08
    • 1970-01-01
    • 2016-03-14
    • 2018-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多