Wscript http post/get in Jscript for PHP

Asked

Viewed 306 times

1

I’m in the mood to make a Jscript script to run by Wscript(native Windows command processor)...

And I have a question: How do I send data in POST or GET (as in a form) to a PHP page?

From now on, thank you.

Edit: Guys the idea is to make a connection to a DB using a PHP page on the web, and using a local script on the computer... Someone?

  • you have the form there?

  • It has no form... It’s actually a file . js that runs by Wscript directly on Windows! It’s not on a web page.

  • 1

    To work you need to know at least the name of the fields to send to the php page. It is possible to do this with powershell, it is simpler.

  • rray teaches me by powershell, because using Wscript I can create a shell object and use its functions. While the fields can be username and password

1 answer

2


In the powershell there is a specific cmdlet to create the Invoke-Webrequest is available from version 3.

Example with get

To send a simple request by simply:

Invoke-WebRequest "http://localhost/teste.php?param1=valor1&param2=valor&param3=valor3"

And let’s say the php page has the following code:

<?php
    echo "<pre>";
    print_r($_GET);

The console output is shown in the figure, various information is shown and can be manipulated like the content which is the server return, statusCode etc.

console get

Example with post

To create a request per post it is necessary to know which fields should be sent to the backend file, this can be obtained by the assignment name of the form fields. Another important point, the information is sent in the body of the request, it will be necessary to create a hash(key/value) and inform the method, by default all requests are get.

$campos = @{"usuario" = "admin"; "senha"=2015}
Invoke-WebRequest "http://localhost/teste.php" -Method Post -Body $campos

Login file:

<?php
    if($_POST['usuario'] == 'admin' && $_POST['senha'] == '2015'){
        echo 'Logado como administrador';
    }else{
        echo 'você não privilegios suficientes';
    }

Console return:

console post

  • Vlw dude. There’s only one thing... Is there any way to run powershell scripts on other computers without having to release the use? Something like a . bat running on any PC(even if there are limitations on the script)... If not, how do I release on my PC? Until.

  • @Superbomber, you say the safety restriction?

  • Yes, is there a way I can run a Powershell script without disabling this restriction?(even if it is limited) And if there’s no way, as deactivated on my PC?

  • 1

    @Superbomber you can run Set-ExecutionPolicy UnRestricted this removes all restrictions, there is another way to pass it in the file, I’m still seeing it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.