Voici quelques méthodes pour effectuer une requête GET/POST





0x01. PHP - CURL


 
function http_post($url, array $post, $cookie, $filter="")
{
  $curl = curl_init($url);
  $ua   = 'Mozilla/5.0 (X11; U; FreeBSD amd64; rv:18.0.0) Gecko/20120101 PC-BSD/9.0 (isotope) Firefox/18.0.0';
 
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl, CURLOPT_COOKIESESSION, true);
  curl_setopt($curl, CURLOPT_USERAGENT, $ua);
  curl_setopt($curl, CURLOPT_COOKIE, $cookie);
  curl_setopt($curl, CURLOPT_POST, true);
  curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
 
  $return = curl_exec($curl);
  if( $filter )          { preg_match($filter,$return,$res); $return = $res[0]; }
  return $return;
}
 

 
function http_get($url, $get="", $filter="") {
 
  static $g_cookie;
  $ch = curl_init($url.$get);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_COOKIE, $g_cookie);
  curl_setopt($ch, CURLOPT_HEADER, 1);
 
  $return = curl_exec($ch);
  preg_match("/Set-Cookie: (PHPSESSID=.+; path=\\/programmation\\/ch1\\/; HttpOnly)/",$return,$res);
 
  if( $g_cookie == "" )  { $g_cookie=$res[1];                                   }
  if( $filter )          { preg_match($filter,$return,$res); $return = $res[0]; }
  return($return);
}
 




0x02. PHP - FILE_GET_CONTENTS


 
function http_get($url, array $context, $cookie, $filter="")
{
  $return = file_get_contents($url, false, $context);
  if( $filter )          { preg_match($filter,$return,$res); $return = $res[0]; }
  return($return);
}
 




0x03. PYTHON - HTTPLIB+URLLIB


 
import httplib, urllib
 
params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
 
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
 
conn = httplib.HTTPConnection("musi-cal.mojam.com:80")
 
conn.request("POST", "/cgi-bin/query", params, headers)
 
response = conn.getresponse()
 
print response.status, response.reason
 
# 200 OK
data = response.read()
conn.close()
 




0x04. PYTHON - URLLIB+URLLIB2


 
import urllib2,urllib
 
# GET:
ret = urllib2.urlopen( urllib.urlencode("http://127.0.0.1/getme.php?var_get=value&var2=value2") )
 
# POST:
ret = urllib2.urlopen( urllib.urlencode("http://127.0.0.1/postme.php") , urllib.urlencode("var_post=value&var_post2=value2") )
 
# POST via array:
ret = urllib2.urlopen( urllib.urlencode("http://127.0.0.1/postme.php") , urllib.urlencode({ "var_post" : "value" , "var_post2" : "value2" }) )
 
 
 



   =>   Écrit par : Nico, le 08 juillet 2015


 
Mots clés :  
  network 
  
  php 
    >   Articles connexes :

GitVuln



HTTP Server, tell me who you are ?


Discuter avec un serveur web *apparement* muet ? Voici comment faire...

Troll The Lamer



Se protéger des injections SQL



6875344