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¶m2=valor¶m3=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.
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:
you have the form there?
– rray
It has no form... It’s actually a file . js that runs by Wscript directly on Windows! It’s not on a web page.
– Silva97
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
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
– Silva97