0
Answered

How to send a http post (including cookie) in JavaScript. What's the syntax?

Abhijeet Ramgir 10 years ago in iRidium Script updated by Sergey (expert) 10 years ago 2
Hello,
I just want to send an HTTP POST (including cookie) to a device. How can I do that using JavaScript?
Thanks,
Abhijeet
Answered
Hi, Abhijeet

It is a syntax example to send Cookie by TCP Driver.


var post = '{"Data1": "value1","Data2":"'value2"}';

var packet = 'POST ' + '/news.html' + ' HTTP/1.0\n' +
'Host: ' + 'www.site.ru'+ ':' + '80' + '\n'+
'Connection: keep-alive\n'+
'Content-Type: application/json\n'+
'User-Agent: Mozilla/3.0 (compatible; Indy Library)\n'+
'Accept-Encoding: identity\n'+
'Content-Length: '+ post.length + '\n\n' + post + '\n' +
'Cookie: income=1';

var Driver = IR.GetDevice("AV & Custom System TCP");

Driver.Send[packet];