The same code under IOS8 No problem, iOS7 can not get the data (will be packet cocoa error 3840 errors), tracking Discovery request head parameter settings regardless of use, according to the text at the bottom of the reference to change the compatibility code:
Code
private Func Getrequest (Method:method, _ urlstring:urlstringconvertible, Parameters: [string:anyobject]? = nil) -> nsmutableurlrequest {Let
request = Nsmutableurlrequest (Url:nsurl (string:URLString.URLString)!)
Request. HttpMethod = method.rawvalue
If parameters!= nil {
request. Httpbody = Nsjsonserialization.datawithjsonobject (parameters!, Options:nil, Error:nil)
}
Request.setValue ( Api_ua, Forhttpheaderfield: "User-agent")
Request.setvalue (header_accept, Forhttpheaderfield: "ACCEPT")
Request.setvalue ("Application/json", Forhttpheaderfield: "Content-type") return
request
}
Here Api_ua and header_accept change to their head parameters, using the code:
var request:request!
If Deviceutils.isios7 () {
request = Mhttpmanager.request (Getrequest (method, URLString, Parameters:parameters))
else {
request = Mhttpmanager.request (method, URLString, Parameters:parameters, encoding:parameterencoding . JSON)
}
//request.responsejson ....
Code Description:
a), Mhttpmanager is manager.sharedinstance, pay attention don't forget to set mHttpManager.session.configuration.HTTPAdditionalHeaders, under IOS8 still works
Reference:
Setting Custom HTTP Headers in Alamofire with IOS 7 not working (reference post, also try setting nsurlsessionconfiguration but no effect)
The above is the Alamofire library under the iOS set head data collation, hoping to help develop the iOS software students.