| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 
 | function post_it ($datastream, $url, $method) {
  $url = preg_replace("@^http://@i", "", $url);
  $host = substr($url, 0, strpos($url, "/"));
  $uri = strstr($url, "/");
 
  $reqbody = "";
  foreach($datastream as $key=>$val) {
    if (!empty($reqbody)) $reqbody.= "&";
    $reqbody.= $key."=".urlencode($val);
  }
 
  if ($method == "GET") {
    $uri .= '?' . $reqbody;
  }
  echo "<br>".$uri."<br>";
  $contentlength = strlen($reqbody);
  $reqheader =  $method . " " . $uri . " HTTP/1.1\r\n".
                "Host: " . $host . "\n".
                "User-Agent: PostIt\r\n".
                "Content-Type: application/x-www-form-urlencoded\r\n".
                "Content-Length: " . $contentlength . "\r\n".
                "Connection: Close\r\n\r\n".
                $reqbody . "\r\n";
 
  $socket = fsockopen($host, 80, $errno, $errstr);
 
  if (!$socket) {
    $result["errno"] = $errno;
    $result["errstr"] = $errstr; 
    return $result;
  }
 
  fputs($socket, $reqheader);
 
  while (!feof($socket)) {
    $result[] = fgets($socket, 4096); 
  }
 
  fclose($socket); 
 
  return $result;
} | 
Partager