[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 315
  • Last Modified:

can anybody see anything wrong in this XML HTTP POST?

Hi,

Thank you for taking a look at my question.  I have the basic html page with a little java in it, all I want to do it post some XML data to an API.  Can anyone see where I am going wrong if anywhere?

This is the only error I can get to come up.
test.com : server does not support RFC 5746, see CVE-2009-3555

Your help is most appreciated!!


<html>
<head>
<script>

function connect(url,params)
{
var $cnct;  // The variable that makes Ajax possible!
try{// Opera 8.0+, Firefox, Safari
alert ("Firefox selected");
$cnct = new XMLHttpRequest();}
catch (e){// Internet Explorer Browsers
try{
$cnct = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e){
try{
$cnct = new ActiveXObject("Microsoft.XMLHTTP");}
catch (e){// Something went wrong
return false;}}}
$cnct.open("POST", "https://api.test.com/PRService.svc/Xml/generate",true);
$cnct.setRequestHeader("Content-type","text/xml");
//$cnct.setRequestHeader($cnct, "close");
$params = '<?xml version="1.0" encoding="utf-8"?><PDRequest xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><MCode>T101</MCode><ACode>TGJHFGDG#%</ACode><RType>Email</RType><PtAmount>300</PaymentAmount><PReference>123456</PReference><CEmail>Yes</CEmail><CReference>No</CReference><RName>J Murphy</RecipientName><REmail>sit@big.com</REmail></PDRequest>';
alert($params);
$cnct.send($params);
alert($cnct.responseText);
alert($cnct.responseBody);
alert($cnct.responseXML);
alert($cnct.getAllResponseHeaders());
//return(connection);
}

</script>
</head>
                 
<body>
    <FORM method="POST" name="ajax" action="">                  
         <INPUT type="BUTTON" value="Submit"  ONCLICK="connect('test','test')">
         <INPUT type="text" name="dyn"  value="">
    </FORM>
 </body>
 </html>
0
mavmanau
Asked:
mavmanau
  • 5
  • 2
1 Solution
 
Gurvinder Pal SinghCommented:
try with simple http rather than https
0
 
mavmanauNetwork Engineer/SysadminAuthor Commented:
it didn't work either...I haven't done anything wrong in the xmlhttprequest at all have I?
0
 
Gurvinder Pal SinghCommented:
where do you get this error? which browser?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mavmanauNetwork Engineer/SysadminAuthor Commented:
firefox.

All I really want to do, is upload some XML - to a REST endpoint.

Can you see anything wrong in how I am going about the connection etc?  from what I have seen it looks to be exactly how it should be in order to work.
0
 
mavmanauNetwork Engineer/SysadminAuthor Commented:
I only see the error in the debug part of firefox.  not sure if it is a warning or an error, from what I have seen on other sites from googling, the system should still try to get through anyway
0
 
hieloCommented:
$cnct.open("POST", "https://api.test.com/PRService.svc/Xml/generate", true);
when you set the third argument to true, you are sending an ASYNCHRONOUS request.  Thus you cannot retrieve the responseText immediately after send() because the request has not completed;

WRONG:
$cnct.send(params);
alert( $cnct.responseText );

For that to work you will need to send a SYNCHRNOUS request instead:
$cnct.open("POST", "https://api.test.com/PRService.svc/Xml/generate", false);

IF you opt to use false instead, then you CAN use:
$cnct.send(params);
alert( $cnct.responseText );


If you actually want to keep true as the third argument (meaning if you really want to use an ASYNCHRONOUS request, you will need to "register" a callback function via the onreadystatechange attribute of the xmlhttp object and monitor the progress of the request.  Once you determine that the request has completed then you then use the responseText.  Here's an implementation of what you are trying to accomplish which CORRECTLY uses true as the third argument:
http://radio.javaranch.com/pascarello/2005/07/20/1121878017742.html
0
 
mavmanauNetwork Engineer/SysadminAuthor Commented:
awesome thank you, I shall have a play with it.
0
 
mavmanauNetwork Engineer/SysadminAuthor Commented:
Thank you for your help!! muchly appreciated.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now