I am trying to implement a specific (and simple) http proxy through PHP. I've been able to get the code to signon to the remote server and process HTTP GET commands with no problems.

However, I am now stumped on the exact format an HTTP POST is formatted to a HTTP server and can't seem to make my code support this method!. I've gone through as many HTTP RFCs I could find. Been through the code to w3c-libwww with no success. If anyone has any suggestions on where I can find this it would be greatly appreciated.

Thanks in advance,
David

    2 months later

    hi,

    I am greatly interested in your project since I am trying to do the same thing on my own =)
    Did you manage to handle the output of a http request correctly ? I mean, how does your proxy behave when you recieve, say, a JPEG image ? I've been trying to sort the http headers from the output, send them to the client (or just the Content-Type: one), save the rest to a temp file and perform a fpassthru(temp) or something like that, but it doesn't appear to work (unless my code is really flawed, and that is quite a possibility =).
    Please E-mail me or contact me so we can talk about our projects.

    Greuh !

      by the way, as far as I know (according to what I found on the net and hacking my netscape =), a POST request should be like that :
      <header 1>
      COntent-type: application/x-form-urlencoded (not sure)
      ...
      <header n>
      <blank line>
      arg1=blah&arg2=blah...

      if you're uploading a file, it is slighlty changed, and you have to create a MIME formatted message (boundaries etc ...).

      as far as I know it works, but I've been to lazy so far to code the upload part =)

      Greuh !

        6 months later

        Dear Greuh and David,

        I'm dealing with what you both has gone through at the moment and I wonder if you already have the solution to support post method via HTTP POST using fsockopen ?

        Currently I'm doing an experiment using PostToHost function to send a HTTP POST request to a server and invoke a script automatically. I manage to get it done but unfortunately, it doesn't allow access outside of the proxy. Have you both had any problem with accessing file that's not from intranet ?

        I wonder if there's any get around about sending HTTP POST via fsockopen and support proxy at the same time as well.

        Hope can discuss with you both together.

        Best regards.

          5 months later

          It would be interesting if we could
          hack the data sent by an browser like netscape during a POST request. I've being trying to find a sort of program (tried netcat) to hack this info and better understand the format.

          The information on w3c is too extensive and I've being looking at it without success for a couple of days so far..

          Anyone to hack this data?

            2 months later

            here's what i do:
            ...
            function HTTP_MSG ($http_msg, $line)
            {
            return $http_msg.$line."\r\n";
            }

            ...

            $host = 'localhost';
            $path = 'test.php';

            $USER = '9bala';
            $PASSWORD = 'sincreto';

            $Message = "Username=$USER&Password=$PASSWORD&login=Login&ssl=";
            $ContentLength = strlen ($Message);

            $msg = HTTP_MSG ($msg, "POST /$path HTTP/1.1");
            $msg = HTTP_MSG ($msg, "HOST: $host");
            $msg = HTTP_MSG ($msg, "ACCEPT: /");
            $msg = HTTP_MSG ($msg, "Referer: http://$host/$path");
            $msg = HTTP_MSG ($msg, "Content-length: $ContentLength");
            $msg = HTTP_MSG ($msg, "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 95)");
            $msg = HTTP_MSG ($msg, "Content-Type: application/x-www-form-urlencoded");
            $msg = HTTP_MSG ($msg, "Connection: Keep-Alive");
            $msg = HTTP_MSG ($msg, "");
            $msg = HTTP_MSG ($msg, $Message);
            $msg = HTTP_MSG ($msg, "");

            $fp = pfsockopen ($host, 80, &$errno, &$errstr, 30);
            if (!$fp) {
            echo "ERROR_STRING=$errstr ERR_NO($errno)<br>\n";
            } else {
            fwrite ($fp, $msg);
            while (!feof($fp)) echo=fgets ($fp,1024);
            fclose ($fp);
            }

              4 months later

              $url="your url";
              $query = "parameters and value passing to be passed with url";

              $request = "POST ".$url." HTTP/1.0\r\n";
              $request = $request ."Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, /\r\n";
              $request = $request ."Referer: your url \r\n";
              $request = $request ."Accept-Language: en-us\r\n";
              $request = $request ."Content-Type: application/x-www-form-urlencoded\r\n";
              $request = $request ."Accept-Encoding: gzip, deflate\r\n";
              $request = $request ."User-Agent: Mozilla/4.61 [ja] (X11; I; Linux 2.2.13-33cmc1 i686)\r\n";
              $request = $request ."Host: www.bluedart.com\r\n";
              $request = $request ."Content-Length: ". strlen($query)."\r\n";
              //proxy authorization........
              $request = $request ."Proxy-Authorization: basic cmFqN3VjOnB===\r\n";
              $request = $request ."Pragma: no-cache\r\n";
              $request = $request ."Connection: keep-alive\r\n\r\n";
              $request = $request . $query."\r\n";

              $line = "";
              $host="your host";
              $connection = @fsockopen($host,80,&$errorNumber,&$errorString,60);
              if(!$connection)
              {
              }
              if ($connection)
              {
              fputs($connection,$request);
              }
              fclose($connection);

                4 months later
                Write a Reply...