嘗試後一些XML。創建一個IBAction爲‘SelectButtonA’,即用Alamofire.request張貼到由struct處理的地址。SOAP編碼。Alamofire .post in Swift。 「調用的結果沒有被使用,但會產生‘DataRequest’
隱而不宣沒有工作,我該如何測試它的發佈,並解決錯誤「調用結果未被使用,但產生'DataRequest'?
//定義Alamofire的SOAP編碼和XML的主結構。 //
struct SOAPEncoding: ParameterEncoding {
let service: String
let action: String
let IRCCC: String = "AAAAAQAAAAEAAABlAw=="
func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest {
var urlRequest = try urlRequest.asURLRequest()
guard parameters != nil else { return urlRequest }
if urlRequest.value(forHTTPHeaderField: "Content-Type") == nil {
urlRequest.setValue("text/xml", forHTTPHeaderField: "Content-Type")
}
if urlRequest.value(forHTTPHeaderField: "SOAPACTION") == nil {
urlRequest.setValue("\(service)#\(action)", forHTTPHeaderField: "SOAPACTION")
}
//let soapArguments = parameters.map({key, value in "<\(key)>\(value)</\(key)>"}).joined(separator: "")
let soapMessage =
"<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/' s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>" +
"<s:Body>" +
"<u:\(action) xmlns:u='\(service)'>" +
IRCCC +
"</u:\(action)>" +
"</s:Body>" +
"</s:Envelope>"
urlRequest.httpBody = soapMessage.data(using: String.Encoding.utf8)
return urlRequest
}
}
@IBAction func SelectButtonA(sender: NSButton) {
Alamofire.request("http://192.168.2.7/sony/IRCC?", method: .post, parameters: ["parameter" : "value"], encoding: SOAPEncoding(service: "urn:schemas-sony-com:service:IRCC:1", action: "X_SendIRCC"))
}
Screenshot of the whole thing. Trying to make a remote.
我檢查了迴應。它產生一個畸形的請求。我固定它。 – yeeeeee