http.postData from a form with httpClient problem

  • 10 years ago

    Hi folks,

    I been asked to post data from a form to a msg broker system being tested by an external team. I have been told that all I should do is post the data using http request in the following format to a server.

    var http =new HttpClient();
    var url="http://P510-4.nottscc.gov.uk:7080/FOI";
    http.contentType = "'text/xml'";
    http.requestHeader = ["SOAPAction", '""'];

    http.postData ='<?xml version="1.0" encoding="UTF-8" ?>';
    http.postData +='<?XML:NAMESPACE PREFIX = SOAPENV /><SOAPENV:ENVELOPE xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
    http.postData +='<SOAPENV:BODY>';
    http.postData +='<?XML:NAMESPACE PREFIX = NS0 /><NS0:SETFOIDATA xmlns:ns0="urn:WSDL5">';
    http.postData +='<NEWFOIREQUEST>';

    http.postData +='';
    http.postData +='<FNAME>'+firstname+'</FNAME>';
    http.postData +='<LNAME>'+surname+'</LNAME>';
    http.postData +=' '+address+'';
    http.postData +='<COUNTY>'+county+'</COUNTY>';
    http.postData +='<POSTCODE>'+postcode+'</POSTCODE>';
    http.postData +='<EMAILADDRESS>'+emailaddress+'</EMAILADDRESS>';
    http.postData +='<TELNO>'+telno+'</TELNO>';
    http.postData +='<REQUESTDETAILS>'+requestdetails+'</REQUESTDETAILS>';
    http.postData +='<REQUESTREFNO>'+requestRef+'</REQUESTREFNO>';
    http.postData +='<SUBMITTEDDATE>'+entryDate+'</SUBMITTEDDATE>';
    http.postData +='</NEWFOIREQUEST>';
    http.postData +='</NS0:SETFOIDATA>';
    http.postData +='</SOAPENV:BODY>';
    http.postData +='</SOAPENV:ENVELOPE>';
    //http.postData = escape(http.postData);

    var sendMyRequest = http.sendRequest(url);

    it posts but breaks off after the first line of the post data

    I've tried posting as he says (see below - the variables are from request strings from the form) but it doesn't accept it.

    var http =new HttpClient();
    &nbsp;&nbsp;
    var url="<A href="http://p510-4.nottscc.gov.uk:7080/FOI">http://P510-4.nottscc.gov.uk:7080/FOI</A>";
    http.contentType = "'text/xml'";
    http.requestHeader = ["SOAPAction", '"<A href="http://p510-4.nottscc.gov.uk:7080/FOI&quot;'">http://P510-4.nottscc.gov.uk:7080/FOI"'</A>];
    var postForm = '';
    postForm ='&lt;?xml version="1.0" encoding="UTF-8" ?&gt;';
    postForm +='&lt;soapenv:Envelope xmlns:soapenv="<A href="http://schemas.xmlsoap.org/soap/envelope/">http://schemas.xmlsoap.org/soap/envelope/</A>" xmlns:xsd="<A href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</A>" xmlns:xsi="<A href="http://www.w3.org/2001/XMLSchema-instance&quot;>'">http://www.w3.org/2001/XMLSchema-instance"&gt;'</A>;
    postForm +='&lt;soapenv:Body&gt;';
    postForm +='&lt;ns0:setFOIData xmlns:ns0="urn:WSDL5"&gt;';
    postForm +='&lt;newFOIRequest&gt;';&nbsp;&nbsp;
    postForm +='&lt;title&gt;'+titleStr+'&lt;/title&gt;';
    postForm +='&lt;fname&gt;'+firstname+'&lt;/fname&gt;';
    postForm +='&lt;lname&gt;'+surname+'&lt;/lname&gt;';
    postForm +='&lt;address&gt;'+address+'&lt;/address&gt;';
    postForm +='&lt;county&gt;'+county+'&lt;/county&gt;';
    postForm +='&lt;postcode&gt;'+postcode+'&lt;/postcode&gt;';
    postForm +='&lt;emailAddress&gt;'+emailaddress+'&lt;/emailAddress&gt;';
    postForm +='&lt;telNo&gt;'+telno+'&lt;/telNo&gt;';
    postForm +='&lt;requestDetails&gt;'+requestdetails+'&lt;/requestDetails&gt;';
    postForm +='&lt;requestRefNo&gt;'+requestRef+'&lt;/requestRefNo&gt;';
    postForm +='&lt;SubmittedDate&gt;'+entryDate+'&lt;/SubmittedDate&gt;';
    postForm +='&lt;/newFOIRequest&gt;';
    postForm +='&lt;/ns0:setFOIData&gt;';
    postForm +='&lt;/soapenv:Body&gt;';
    postForm +='&lt;/soapenv:Envelope&gt;';
    http.postData = postForm;</P> <P>var sendMyRequest = http.sendRequest(url);


    Can anyone tell me why this does not work please. I am fairly new to XML and would appreciate any help.

    Thanks



  • 10 years ago

    Your definition of the soapenv namespace looks like it might be being constructed incorrectly.  If you can, re-write it such that it looks closer to this:

    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope
      xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <soapenv:Header>
      </soapenv:Header>
      <soapenv:Body>
      </soapenv:Body>
    </soapenv:Envelope>








    You left a few links open in the original posting, I had trouble replying to it!

    HTH

  • 10 years ago

    Hi CAMURPHY,   

    Thanks for the reply.

    The client said that she has made the changes to the soapenv namespace with no success.

    She said she still gets no response or result code.

    HTTP response header is:

    Has request sent should be true if HTTP result code is 200
    Has request sent?: false
    HTTP result code: 0



    Any ideas?

    Do you need anymore information?

    Thanks

     

     

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” - Tom Cargill