1

This is my code for calling URL

@if (@This==@IsBatch) @then
@echo off


    setlocal enableextensions disabledelayedexpansion



        wscript //E:JScript "%~dpnx0" "http://abcd.com/xyz=lo" 



    exit /b

@end

var http = WScript.CreateObject('Msxml2.XMLHTTP.6.0');


var url = WScript.Arguments.Item(0)



    http.open("GET", url, false);
    http.send();


    WScript.Quit(0);

This calls the url http://abcd.com/xyz=lo only once

Now I wanted to call the URL if the reponse code is 200 so I did like this

:loop
    http.open("GET", url, false);
    http.send();

if(http.status==200)
{

}
else
{
goto loop
}

But its not working(its not calling the url even if the status is 400)

SpringLearner
  • 13,738
  • 20
  • 78
  • 116

1 Answers1

0

Try with

....
do {
    try {
        http.open('GET', url, false);
        http.send();
    } catch (e){
    }
} while (http.status != 200);
....
MC ND
  • 69,615
  • 8
  • 84
  • 126
  • why cant I use in my way? – SpringLearner May 11 '15 at 09:24
  • @SpringLearner, because the code executing the http request is javascript, and in javascript `goto` is not a valid statement. – MC ND May 11 '15 at 09:28
  • yes I thought the same but even If I write console.log("ss") then also its not working.console.log() is a valid statement – SpringLearner May 11 '15 at 09:39
  • @SpringLearner, `console` is not a native javascript object. It is exposed by host (the program not the machine) running the script. Your code is using the Windows Scripting Host (WSH) to run the script. This host does not include `console` object. If you want to output something, use `WScript.Echo`, where `WScript` is a "root" object exposed by the host and `Echo` is the method to output information. – MC ND May 11 '15 at 09:52
  • well this is not my code,I was following one of your answers http://stackoverflow.com/a/20787029/2664200 .yes I have also tried with WScript.Echo, for example to know the status I did WScript.Echo status but I got an error – SpringLearner May 11 '15 at 09:56
  • @SpringLearner, yes, i know the original code is mine.But (a) it was written as an example and in the answer is included *`"...No error check, no post, just a skeleton..."`* and (b) It didn't include any output. If you need the output, start with `WScript.Echo(http.status)`. Note that the `status` property can not be retrieved until the `send` method is invoked. – MC ND May 11 '15 at 10:06