ios - alamofire 通过 SOAP 发送请求

标签 ios swift soap alamofire

我使用 alamofire 。在将代码转换为 swift3 之前,一切正常,但是在调用我的方法时转换为 swift3 之后......数据为空。

getRequest 返回一个 NSMutableURLRequest :

private func getRequest(_ soapAction: String, urlService: URL, methodName: String, params: NSArray?) -> NSMutableURLRequest {
    var newSoapMessage = ""

    if let _ = params {
        newSoapMessage = getSoapMessage(methodName, params: params!)
    } else {
        newSoapMessage = getSoapMessage(methodName)
    }

    request = NSMutableURLRequest(url: urlService)
    lengthSoapMessage = String(newSoapMessage.characters.count)

    request.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type")
    request.addValue(lengthSoapMessage, forHTTPHeaderField: "Content-Length")
    request.addValue("Basic \(accountBase64)", forHTTPHeaderField: "Authorization")
    request.addValue(soapAction, forHTTPHeaderField: "SoapAction")
    request.httpMethod = "POST"
    request.httpBody = newSoapMessage.data(using: String.Encoding.utf8)

    return request
}

现在:

var request = getRequest(soapAction,urlService: Common.urlShatelService! as URL, methodName: methodName, params: params)



    Alamofire.request(request as! URLRequestConvertible).responseData { response in
        switch response.result {
        case .success(let value):
            let result = Result.success(value)
            callBack(result)
            break
        case .failure:
            let result = Result<Data>.failure
            callBack(result)
            print("exception: \(response.result.error)")
            break
        }
    }

在转换之前,alamofire 接受请求但在转换之后我必须转换为 URLRequestConvertible !!!!

现在。调用 alamofire 时返回此异常:

2016-09-27 17:17:57.267619[3454:1060477] Could not cast value
 of type 'NSMutableURLRequest' (0x101e445b8) to 
'Alamofire.URLRequestConvertible' (0x101e400b0).

最佳答案

我遇到了同样的问题。 尝试将 NSMutableURLRequest 类型更改为 URLRequest。

request = URLRequest(url: urlService)

关于ios - alamofire 通过 SOAP 发送请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39726352/

相关文章:

java - SSLHandshakeException : No subject alternative names present

ios - 解析服务器:我需要在防火墙中打开哪些端口来发送ios推送通知? (APNS)

swift - 快速制作简单的 Accordion TableView?

ios - "Code signing "GoogleToolboxForMac.framework "failed"上传到 Itunes Connect 时

swift - Swift 3 中预期参数类型 UnsafeMutablePointer<_> 的 UnsafeMutablePointer

ios - 只允许 UIScrollView 缩放弹跳时放大,不缩小

c# - 请求失败,响应为空。在 Loadbalancer 后面调用 ASMX 服务

java - 在 Soap 响应中读取 XML 时出现错误的命名空间(非空)

ios - UIBottom 文本字段未设置

ios - 创建 NSManagedObject 的副本