3.0 beta 2

Sending Data over HTTP?

Is it possible to send data via Active.HTTP.Request?

Using the FF HTTPRequest the ability to send data was performed like:

var _connectionObject = new XMLHttpRequest();
_connectionObject.onreadystatechange = _xht_StateChange;
_connectionObject.open("POST", url, true);
_connectionObject.send(xmlBody.toString()); // <-- Send the xmlBody string


Any ideas?

Stephane
March 15,
i made a soap javascript to PHP test. You need PHP 5.x for soap server part.
if you leave the soap overhead it will also work with PHP 4.x

this is the code-snippet for crossbrowser XMLHttpRequest
xmlhttpreq.js
var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false
  }
 }
@else
 xmlhttp=false
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttp = new XMLHttpRequest();
 } catch (e) {
  xmlhttp=false
 }
}

i guess that is what you needed.... :)

for others to complete an example,
this is the Soap XMLHttpRequest transmission in javascript
client.htm
<head>
<script src='xmlhttpreq.js'></script
<script>
function xmit(data){
 xmlhttp.open("POST", "url/server.php",true);
 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
   document.getElementById("sushi").innerHTML = xmlhttp.responseText;
  }
 }
 xmlhttp.setRequestHeader("Man", "GET url/server.php HTTP/1.1")
 xmlhttp.setRequestHeader("MessageType", "CALL")
 xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8")
 // xmlhttp.setRequestHeader("SOAPAction", "url/server.php")

 xmlhttp.send(
  "<"+"?xml version ='1.0' encoding ='UTF-8' ?"+">\n " +
  "<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ns1='urn:localhost-temperature'"+ "xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:SOAP-"+
  "ENC='http://schemas.xmlsoap.org/soap/encoding/' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>"+
  "<SOAP-ENV:Body>"+
  "<ns1:getTemp>"+
  "<symbol xsi:type='xsd:string'>data</symbol>"+
  "</ns1:getTemp>"+
  "</SOAP-ENV:Body>"+
  "</SOAP-ENV:Envelope>"
   );
}
 </script>
 </head>
 <body>
 <input type='text' id='seg'>
 <input type='button' onclick='xmit(document.getElementById("seg").value)' name='' value ='test'>
 <div id='sushi'></div>
 </body>


and here is the server side php code
server.php
<?php
  // this is for debugging, as it is hard to do it
 $fp = fopen("trace_data.txt", "w+");
 fwrite($fp, "[". $HTTP_RAW_POST_DATA . "]\n". print_r($GLOBALS, true)); 
 fclose($fp);
 // end debugging
 
 function getTemp($zip) {
  global $f;
  $temp = rand(40,80);
  return $temp;
 }
  
 $server = new SoapServer("temperature.wsdl");
 $server->addFunction("getTemp");
 $server->handle();
 ?>


and as last snippet the wdsl definition for the soap example as
temperature.wsdl
<?xml version ='1.0' encoding ='UTF-8' ?> 
 <definitions name='Temperature' 
   targetNamespace='http://example.org/temperature' 
   xmlns:tns=' http://example.org/temperature ' 
   xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' 
   xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
   xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' 
   xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/' 
   xmlns='http://schemas.xmlsoap.org/wsdl/'> 
  <message name='getTempRequest'> 
   <part name='symbol' type='xsd:string'/> 
 </message> 
 <message name='getTempResponse'> 
   <part name='Result' type='xsd:string'/> 
 </message> 
  <portType name='TempPortType'> 
   <operation name='getTemp'> 
     <input message='tns:getTempRequest'/> 
     <output message='tns:getTempResponse'/> 
   </operation> 
 </portType> 
  <binding name='TempBinding' type='tns:TempPortType'> 
   <soap:binding style='rpc' 
     transport='http://schemas.xmlsoap.org/soap/http'/> 
   <operation name='getTemp'> 
     <soap:operation soapAction='urn:localhost-temperature#getTemp'/> 
     <input> 
       <soap:body use='encoded' namespace='urn:localhost-temperature' 
         encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 
     </input> 
     <output> 
       <soap:body use='encoded' namespace='urn:localhost-temperature' 
         encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 
     </output> 
   </operation> 
 </binding> 
  <service name='TemperatureService'> 
   <port name='TempPort' binding='TempBinding'> 
     <soap:address location='http://www.umweg.ch/soap/server.php'/> 
   </port> 
 </service>
</definitions>


i took the infos from:
http://jibbering.com/2002/4/httprequest.html
http://www.devx.com/webdev/Article/22338/0/page/4
http://www.zend.com/php5/articles/php5-SOAP.php?article=php5-SOAP&kind=php5&id=5085&open=1&anc=0&view=1

and in the very short way:
client2.htm
<script src='xmlhttpreq.js'></script
<script>
function xmit(data){
 xmlhttp.open("POST", "url/server2.php",true);
 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
   document.getElementById("sushi").innerHTML = xmlhttp.responseText;
  }
 }
 xmlhttp.setRequestHeader("Man", "GET url/server2.php?data="+data+" HTTP/1.1")
 xmlhttp.send("");
}
 </script>


server2.php
<?php
import_request_variables("gp", "d_");
echo $d_data;
?>

Andres Obrero [Winterthur]
March 15,

This topic is archived.

See also:


Back to support forum

Search

Version 2

Looking for AW 2.6 ?
The old site is here.