I'm new to stack overflow and fairly new to programming so bear with me. I apologize in advance for any typos.
Planning to use C#
console application to extract data from a Web API.
Did not find alot of information on how to execute a javascript function from the .cs file. So i decided to try out Microsoft Script Control.
I am trying to send a xmlhttpRequest
using Microsoft Script Control. But I keep getting
"XMLHttpRequest is undefined".
ScriptControl js = new ScriptControl();
js.AllowUI = false;
js.Language = "JScript";
js.Reset();
js.AddCode(@"
function test()
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('GET', 'WEB API LINK', true);
xmlhttp.send();
xmlhttp.addEventListener('readystatechange', processRequest, false);
xmlhttp.onreadystatechange = processRequest;
function processRequest(e)
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
var response = JSON.parse(xmlhttp.responseText);
return response;
}
}
}
}
");
Not sure if this even works with Script Control. When using the script in a regular html page inside <script> </script>
it works except that I havent been able to send data or retrieve data from .html to .cs. Any different routes would be appreciated.
Regards RiceNor