web services - Write full HTTP POST request packet -
i need write full http request invoke soap service. don't have libraries soap request need write full http packet. how i've proceeded (i'm programming arduino board):
string body = httprequestbody("33", "77%"); client.println("post /dataserver http/1.1"); client.println("accept: text/xml, multipart/related"); client.println("content-type: text/xml; charset=utf-8"); client.println("soapaction: \"http://example.com/functions/senddatarequest\""); client.println("user-agent: arduino wifishield"); client.println("content-length: "+body.length()); client.println("host: arduino-data-server.appspot.com/dataserver"); client.println("connection: keep-alive"); client.println(); client.println(body);
client represent connection webservice. httprequestbody function:
string httprequestbody(string v1, string v2) { serial.println("generating xml message..."); string res = ""; res += "<?xml version=\"1.0\"?>\n\r"; res +="<s:envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"\n\r"; res +="<s:body>\n\r"; res +="<ns2:senddata xmlsn:ns2=\"http://example.com\">\n\r"; res +="<arg0>"+v1+"</arg0>\n\r"; res +="<arg1>"+v2+"</arg1>\n\r"; res +="</ns2:senddata>\n\r"; res +="</s:body>\n\r"; res +="</s:envelope>\n\r"; serial.println(res); return res; }
but gone wrong , can't contact webserver. webserver works , it's reacable, because if change post get, on webservice log, see connection. how can fix it?
in httprequestbody allocating: string res = "";
, updating it. finally, return res
. but, res
allocated on stack of httprequestbody (??), not guaranteed there after httprequestbody terminates.
you need c++ equivalent of malloc used in c code, in order ensure res on heap , not freed.
Comments
Post a Comment