我正在使用Alamofire,使用HTTP导致没问题,但是当我将协议HTTP更改为HTTPS时,我得到了以下内容
错误域= NSPOSIXErrorDomain代码= 100"协议错误" UserInfo = {NSErrorPeerAddressKey = {length = 16,capacity = 16,bytes = 0x100201bb5d5efc420000000000000000},_ kCFStreamErrorCodeKey = 100, _kCFStreamErrorDomainKey = 1})
Cod我试过:
public init(){}
static let shared = HTTPRequest()
func Service(method:String,path:String,
parameters:[String:String]? = nil,
requestObj:Any? = nil,
actionListener:ActionListener){
actionListener.start()
var _url = URLComponents(string: BaseURL + path)
if parameters != nil{
var queryItems = [URLQueryItem]()
for parameter in parameters!{
let queryItem = URLQueryItem(name: parameter.key, value: parameter.value)
queryItems.append(queryItem)
}
_url?.queryItems = queryItems
}
var request = URLRequest(url: (_url?.url)!)
request.httpMethod = method
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
if MobileConstants.AccessToken != nil{
request.setValue(MobileConstants.AccessToken, forHTTPHeaderField:"Authorization")
request.setValue(MobileConstants.LoginResponse.user.userName, forHTTPHeaderField: "UserName")
}
request.setValue("iOS", forHTTPHeaderField: "ClientToken")
request.setValue("en-US", forHTTPHeaderField: "Language")
if(requestObj != nil){
let json = JSONSerializer.toJson(requestObj!)
request.httpBody = json.data(using: .utf8)
}
Alamofire.request(request).responseJSON {
response in
if(response.result.isSuccess){
actionListener.success(from: path, data: response.result.value!)
}else{
actionListener.fail()
print(response.error)
print(response.result.error)
}
}
}
答案 0 :(得分:0)
这不是根本的解决方案,我用...解决了它。
将以下内容添加到apache的httpd.conf
Header unset Upgrade
然后重新启动
答案 1 :(得分:0)
我遇到了这个问题,然后我发现问题出在HTTP正文中,当HTTP方法为GET时,我将HTTP正文设置为nil