0
我需要構建SOAP請求以請求存儲在Google App Engine上的webservice,因爲我工作的平臺沒有用於管理webservice請求的庫(我正在編寫Arduino Board )。 我SOAP服務器將存放在手動構建SOAP服務請求
http://arduino-data-server.appspot.com/
,我需要連接到服務器之前發送請求。這是我的代碼:
char server[] = "www.arduino-data-server.appspot.com"; //server address
WiFiClient client;
if(client.connect(server, 80)) {
Serial.println("Connected to server, preparing request");
client.println("POST /dataserver HTTP/1.1");
client.println("Host: http://arduino-data-server.appspot.com");
client.println("Content-Type: text:xml; charset=utf-8");
client.println("SOAPAction: \"http://example.com/getData\"");
client.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
client.println("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
client.println("<soap:Body>");
client.println("<sendData xmlns=\"http://example.com/\"");
client.println("<temperatura> 22 </temperatura>");
client.println("<umidita> 55 </umidita>");
client.println("</sendData>");
client.println("</soap:Body>");
client.println("</soap:Envelope>");
client.println();
Serial.println("OK");
}else {
Serial.println("KO");
}
}
everithing似乎是確定的,但我的服務器上,未檢測到傳入連接。怎麼了?
這WSDL文件:arduino-data-server.appspot.com/FunctionsService.wsdl
問題是我錯過了POST方法的「content-lenght」主體屬性。如果該字段不正確或缺失,服務器不處理http數據包。只需在一個單獨的函數中生成http主體,以便計算長度屬性並將其附加到請求 – giozh