无法使用 alamofire 4 上传带参数的图像?

Posted

技术标签:

【中文标题】无法使用 alamofire 4 上传带参数的图像?【英文标题】:Unable to upload image with parameters using alamofire 4? 【发布时间】:2017-04-04 20:35:52 【问题描述】:

在使用 alamofire 4 上传带有参数的图像时,得到以下结果:

Alamofire.DefaultDataResponse(request: url, response: Optional(<NSHTTPURLResponse: 0x17523cde0>  URL: rl  status code: 409, headers 
    "Cache-Control" = "no-cache";
    Connection = "keep-alive";
    "Content-Length" = 32;
    "Content-Type" = "application/json";
    Date = "Tue, 04 Apr 2017 20:23:50 GMT";
    Server = "nginx/1.8.1 + Phusion Passenger 4.0.60";
    Status = "409 Conflict";
    Vary = Origin;
    "X-Powered-By" = "Phusion Passenger 4.0.60";
    "X-Request-Id" = "4bd65f3e-9cae-4f69-8d5f-139dfed6c148";
    "X-Runtime" = "0.490166";  ), data: Optional(32 bytes), error: nil, timeline: Timeline:  "Request Start Time": 513030074.617, "Initial Response Time": 513030127.999, "Request Completed Time":
513030230.298, "Serialization Completed Time": 513030230.303, "Latency": 53.382 secs, "Request Duration": 155.681 secs, "Serialization Duration": 0.005 secs, "Total Duration": 155.686 secs , _metrics: Optional((Task Interval) <_NSConcreteDateInterval: 0x17163b000> (Start Date) 2017-04-04 20:21:14 +0000 + (Duration)
155.679614 seconds = (End Date) 2017-04-04 20:23:50 +0000 (Redirect Count) 0 (Transaction Metrics) (Request) <NSURLRequest: 0x170202da0>  URL: url   status code: 409, headers 
    "Cache-Control" = "no-cache";
    Connection = "keep-alive";
    "Content-Length" = 32;
    "Content-Type" = "application/json";
    Date = "Tue, 04 Apr 2017 20:23:50 GMT";
    Server = "nginx/1.8.1 + Phusion Passenger 4.0.60";
    Status = "409 Conflict";
    Vary = Origin;
    "X-Powered-By" = "Phusion Passenger 4.0.60";
    "X-Request-Id" = "4bd65f3e-9cae-4f69-8d5f-139dfed6c148";
    "X-Runtime" = "0.490166";   (Fetch Start) 2017-04-04 20:22:07 +0000 (Domain Lookup Start) 2017-04-04 20:22:07 +0000 (Domain Lookup End) 2017-04-04 20:22:07 +0000 (Connect Start) 2017-04-04 20:22:07
+0000 (Secure Connection Start) (null) (Secure Connection End) (null) (Connect End) 2017-04-04 20:22:07 +0000 (Request Start) 2017-04-04 20:22:07 +0000 (Request End) 2017-04-04 20:23:48 +0000 (Response Start) 2017-04-04 20:23:50 +0000 (Response End) 2017-04-04 20:23:50
+0000 (Protocol Name) http/1.1 (Proxy Connection) NO (Reused Connection) NO (Fetch Type) Network Load

什么都不懂。图像未上传,但得到了这些响应。如果有人遇到此类问题,请提供帮助。

【问题讨论】:

【参考方案1】:

我必须将参数作为正文发送,但默认情况下尝试它不是导致错误的正文请求。

【讨论】:

以上是关于无法使用 alamofire 4 上传带参数的图像?的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Swift 4 中使用 Alamofire 上传具有其他参数的多个图像

如何使用 multipartFormData 和参数上传图像,使用 Alamofire 4.3 请求所需的身份验证

带有 MultiPart 表单数据中的参数的图像上传在 Alamofire 4.0 中不起作用

在IOS中上传带参数的多部分图像

使用 Alamofire 上传图像的问题(将图像作为参数)

如何使用 alamofire 和数组形式的参数上传图像