0

I have no programming experience on how to get this done, any help would be greatly appreciated

So there is a command that if I paste into my browser it executes and the job is done. It is a JSON API request that connects to the localhost to an application listening on port 8080, the command (1) is outlined below

http://localhost:8080/jsonrpc?request={"jsonrpc":%20"2.0",%20"id":%201,%20"method":"System.Shutdown"}

When I paste this code as is into a browser it will execute the system shutdown task as expected (provided the program that is listening is running)

Im am having trouble converting this command into a batch file that can be executed using task scheduler or a simple double click. I have tried the command below (2) in a batch file using CMD but it just ignores the quotation marks and I get a parsing error as a result(3).

CMD command (2)

start http://localhost:8080/jsonrpc?request={"jsonrpc":%20"2.0",%20"id":%201,%20"method":"System.Shutdown"}

Resulting error (3)

{"error":{"code":-32700,"message":"Parse error."},"id":null,"jsonrpc":"2.0"}

and the url looks like this (4)

http://localhost:8080/jsonrpc?request={jsonrpc:02.0,0id:01,0method:System.Shutdown}

All the quotation marks above (4) are gone, I suppose API JSON requests (I think they are called that) are sensitive to these sort of issues.

I have tried the command (1) in powershell and it wont have it. Resulting error below (5)

At line:1 char:49 + http://localhost:8080/jsonrpc?request={"jsonrpc":%20"2.0",%20"id":%20 ... + ~~~~~~~~~ Unexpected token ':%20"2.0"' in expression or statement. At line:1 char:58 + http://localhost:8080/jsonrpc?request={"jsonrpc":%20"2.0",%20"id":%20 ... + ~ Missing argument in parameter list. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnexpectedToken

All I need is a script that if double clicked or triggered using task scheduler will execute and issue that command (1) to the local host ie paste the command as is into a browser or skip the browser and go directly.

I going to admit im a total noob at this so a simple step by step guide on how to set this up will be of massive help. Im fairly certain though, that this is a straight forward task for a lot of you :) Im really looking forward to your answers.

  • LotPings, thanks for your help but im still getting error (3) this is what the resulting url is http://localhost:8080/jsonrpc?request={\jsonrpc\:%%20\2.0\,%%20\id\:%%201,%%20\method\:\System.Shutdown\} – trevor Feb 28 at 21:52
0

I see some issues:

  1. start needs a dummy pair of double quotes for the title
  2. cmd interprets all percent signs as enclosing variables, => double them to escape.
  3. double quote the whole url and escape inner ones with a backslash

so try:

start "" "http://localhost:8080/jsonrpc?request={\"jsonrpc\":%%20\"2.0\",%%20\"id\":%%201,%%20\"method\":\"System.Shutdown\"}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.