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¶m2=valor¶m3=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,thiscanbeobtainedbythename
oftheformfields.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: