WScript http post / get in JScript for PHP

1

I am trying to do a script in JScript to be executed 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?

Thanks in advance.

Edit: 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 ... Anyone?

    
asked by anonymous 03.10.2015 / 21:51

1 answer

2

In powershell there is a specific cmdlet to create requisitions Invoke-WebRequest is available from of version 3.

Example with get

To submit a simple request at once:

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

And let's say that the php page has the following code:

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

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

Examplewithpost

Tocreatearequisitionperpostitisnecessarytoknowwhichfieldsaretobesenttothebackendfile,thiscanbeobtainedbythenameoftheformfields.Anotherimportantpoint,theinformationissentintherequestbody,itwillbenecessarytocreateahash(key/value)andinformthemethod,bydefaultallrequestsareget.

$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:

    
07.10.2015 / 06:04