das*_*ble 10 cookies nsurlrequest swift alamofire swift2
我想在我的HTTP POST请求中设置cookie.
类似于下面的HTTP请求中的cookie字段,
version: 0.1.7
Cookie: client=Android; version=0.1.7; sellerId=SEL5483318784; key=178a0506-0639-4659-9495-67e5dffa42de
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 1431
Run Code Online (Sandbox Code Playgroud)
如何通过Alamofire实现这一目标?
我目前的Alamofire请求是这样的,
Alamofire.request(.POST, ServerConfig.ADD_PRODUCT_URL, parameters: productJSON, encoding: .JSON, headers: nil)
.responseJSON(completionHandler: { responseRequest, responseResponse, responseResult in
print(responseRequest!.URL)
print(responseResponse)
print(responseResult)
})
Run Code Online (Sandbox Code Playgroud)
Jér*_*rin 18
我在项目上遇到了同样的问题,我做了类似这样的事情来解决它:
let cookies = NSHTTPCookie.cookiesWithResponseHeaderFields(response.allHeaderFields as! [String: String], forURL: response.URL!)
Alamofire.Manager.sharedInstance.session.configuration.HTTPCookieStorage?.setCookies(cookies, forURL: response.URL!, mainDocumentURL: nil)
Run Code Online (Sandbox Code Playgroud)
你只需要这样做一次,因为Alamofire实例是一个单例,所以对于所有下一个请求都设置了cookie.
希望这是你要找的:)
| 归档时间: |
|
| 查看次数: |
9117 次 |
| 最近记录: |