question

Upvotes
Accepted
41 2 2 2

How to make html POST to IDS

Background. I have IDS server running on host padh4, port 8500. I want to request a snapshot from IDS, and filter FIDs BID and ASK.

The following works ok from the command line:

COMMAND:
curl "http://padh4:8500/ids-rest/json/quote/" -d '{"item": ["CSCO.O"],"filter": ["BID","ASK","TRDPRC_1"],"service": "IDN_RDF","token": "rharris"}'
RESULT:
{"stsCode":0,"stsTxt":"OK","result":[{"_service":"IDN_RDF","_qos":"RT0","_item":"CSCO.O","stsCode":0,"stsTxt":"OK","chainLink":[],"TRDPRC_1":"53.68","BID":"53.68","ASK":"53.69"}]}

I am trying to achieve the same result with an html page, code shown below.

<html>
<head>
<title>Form Example</title>
<script LANGUAGE="JavaScript" type="text/javascript">
function display() {
  message = "{"; 
  message += "\"item\" :"        + document.form1.item.value        + ",";
  message += "\"filter\" :"      + document.form1.filter.value      + ",";
  message += "\"service\" :"     + document.form1.service.value     + ",";
  message += "\"user\" :"        + document.form1.user.value        + ",";
  message += "\"expandChain\" :" + document.form1.expandChain.value + ",";
  message += "\"emptyLink\" :"   + document.form1.emptyLink.value   + ",";
  message += "\"chainLink\" :"   + document.form1.chainLink.value;
  message += "}";
 
  var form = document.createElement("form");
  form.setAttribute("method", "post");
  form.setAttribute("action", "http://padh4:8500/ids-rest/json/quote/");
  var hiddenField = document.createElement("input");
  hiddenField.setAttribute("type", "hidden");
  hiddenField.setAttribute("name", "key");
  hiddenField.setAttribute("value", message);
  form.appendChild(hiddenField);
  document.body.appendChild(form);
  form.submit();
}
</script>
</head>
<body>
<h1>Form Example</h1>
Enter the following information. When you press the Display button,
the data you entered will be displayed in a pop-up window.
<form name="form1">
<p><b>Item:</b> <input TYPE="TEXT" SIZE="20" NAME="item">
</p>
<p><b>Filter:</b> <input TYPE="TEXT" SIZE="30" NAME="filter">
</p>
<p><b>Service: </b> <input TYPE="TEXT" SIZE="15" NAME="service">
</p>
<p><b>User: </b> <input TYPE="TEXT" SIZE="15" NAME="user">
</p>
<p><b>Expand Chain: </b> <input TYPE="TEXT" SIZE="15" NAME="expandChain">
</p>
<p><b>Empty Link: </b> <input TYPE="TEXT" SIZE="15" NAME="emptyLink">
</p>
<p><b>Chain Link: </b> <input TYPE="TEXT" SIZE="15" NAME="chainLink">
</p>
<p><input TYPE="BUTTON" VALUE="Send POST" onClick="display();"></p>
</form>
</body>
</html>

This page connects to padh4 on port 8500 ok, and seems to make the POST ok. The javascript takes the form data and builds a string, which is submitted via a hidden table. However, IDS returns the following error:

{"stsCode":402,"stsTxt":"PARSE_UNICODE_ERROR"}

The chrome debugger shows my POST was submitted as the value to a variable called "key". The format is close but not correct, hence the 402 error from IDS.

My issue is how to get the POST correctly formatted. Do I need to JSON.stringify the message? Or build it completely manually? How to get rid of the 'key' in the response?

Thanks in advance for all help.

elektronrefinitiv-realtimetrepjavascriptposthtml
capture.png (49.1 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

@billy.w.cunningham

Hi,

Thank you for your participation in the forum.

Are any of the replies below satisfactory in resolving your query?

If yes please click the 'Accept' text next to the most appropriate reply. This will guide all community members who have a similar question.

Otherwise please post again offering further insight into your question.

Thanks,

AHS

@billy.w.cunningham

Hi,

Thank you for your participation in the forum.

Are any of the replies below satisfactory in resolving your query?

If yes please click the 'Accept' text next to the most appropriate reply. This will guide all community members who have a similar question.

Otherwise please post again offering further insight into your question.

Thanks,

AHS

Please be informed that a reply has been verified as correct in answering the question, and has been marked as such.

Thanks,

AHS

Upvotes
Accepted
41 2 2 2

Gurpreet, we got the answer. The file item_input.html, which comes with IDS, shows how to construct the POST message and submit it correctly. Thanks for all your help.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
22.1k 59 14 21

@billy.w.cunningham I don't have an IDS to test it out anymore, but it looks like that the form message you are submitting is incorrect. There are additional + in the form data and form values aren't in double quotes either.

You are also missing the token key - which is present in the CURL command.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
41 2 2 2

Thanks Gurpreet, i did change 'user' to 'token'. I still need to get rid of the +s and that should be pretty close.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
41 2 2 2

This curl command works fine with IDS:

curl "http://padh3:8500/ids-rest/json/quote/" -d '{"item": ["CSCO.O"],"filter": ["BID","ASK","TRDPRC_1"],"service": "IDN_RDF","token": "rharris"}'

Is there a way to get this same result from an html form?

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
22.1k 59 14 21

I'll try to create a sample form and post here.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
22.1k 59 14 21

Hi @billy.w.cunningham You can try the attached sample. I am not able to test it because of no access to IDS, so you might have to tweak it.

idstest.zip


idstest.zip (917 B)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.