Code:
/**
* This function sends a Post Request with the data we want to send
* @param host (acceptor server adress)
* @param port (what port are you using 80, 8080)
* @param path (path where to put the data)
* @param data_to_send (the xml we want to sent)
* @return res (response from server)
*/
function PostToHost($url, $timeout, $data_to_send) {
$idx = strrpos($url, ":");
$host = substr($url, 0, $idx);
$url = substr($url, $idx + 1);
$idx = strpos($url, "/");
$port = substr($url, 0, $idx);
$path = substr($url, $idx);
//print $host . " - " . $port . " - " . $path . ".";
// Regel uitgecommentaard, class functie is niet aanwezig in dit sample
// $this->log("sending to " . $host . ":" . $port . $path . ": " . $data_to_send);
$fsp = fsockopen($host, $port, $errno, $errstr, $timeout);
if($fsp) {
fputs($fsp, "POST $path HTTP/1.0\r\n");
fputs($fsp, "Accept: text/html\r\n");
fputs($fsp, "Accept: charset=ISO-8859-1\r\n");
fputs($fsp, "Content-Length:".strlen($data_to_send)."\r\n");
fputs($fsp, "Content-Type: text/html; charset=ISO-8859-1\r\n\r\n");
fputs($fsp, $data_to_send, strlen($data_to_send));
while(!feof($fsp)) {
$res .= fgets($fsp, 128);
}
fclose($fsp);
// Regel uitgecommentaard, class functie is niet aanwezig in dit sample
// $this->log("receiving from " . $host . ":" . $port . $path . ": " . $res);
return $res;
}
else {
// Regel uitgecommentaard, class functie is niet aanwezig in dit sample
// $this->log("error from " . $host . ":" . $port . $path . ": " . $errstr);
return "Error: " . $errstr;
}
}
function PostToHostProxy($proxy, $url, $timeout, $data_to_send) {
$idx = strrpos($proxy, ":");
$host = substr($proxy, 0, $idx);
$idx = strpos($proxy, ":");
$port = substr($proxy, $idx+1);
// Regel uitgecommentaard, class functie is niet aanwezig in dit sample
// $this->log("sending to " . $host . ":" . $port . ": " . $data_to_send);
$fsp = fsockopen($host, $port, $errno, $errstr, $timeout);
if($fsp) {
fputs($fsp, "POST $url HTTP/1.0\r\n");
//fputs($fsp, "Host:www.acrm.de:443\r\n");
fputs($fsp, "Accept: text/html\r\n");
fputs($fsp, "Connection: Close\r\n");
fputs($fsp, "Accept: charset=ISO-8859-1\r\n");
fputs($fsp, "Content-Length:".strlen($data_to_send)."\r\n");
fputs($fsp, "Content-Type: text/html; charset=ISO-8859-1\r\n\r\n");
fputs($fsp, $data_to_send, strlen($data_to_send));
while(!feof($fsp)) {
$res .= fgets($fsp, 128);
}
while(!feof($fsp)) {
$res .= fgets($fsp, 128);
}
fclose($fsp);
// Regel uitgecommentaard, class functie is niet aanwezig in dit sample
// $this->log("receiving from " . $host . ":" . $port . $path . ": " . $res);
return $res;
}
else {
// Regel uitgecommentaard, class functie is niet aanwezig in dit sample
// $this->log("error from " . $host . ":" . $port . $path . ": " . $errstr);
return "Error: " . $errstr;
}
}
Gebruik dit om het te posten uiteindelijk,
Code:
PostToHost("https://mijnurl:443/", 15, $xml);
PostToHostProxy("http://proxy_server:8080/", "https://mijnurl:443/", 15, $xml);
Functies geven de teruggekregen waardes 1:1 terug, tenzij er een fout is.