how does one send a large string as a POST to another web page?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lawrence k

    how does one send a large string as a POST to another web page?

    If I've a big string and I want to send it to another web page as a GET
    request, I just use file(). I've done this often.

    But what command do I use when I want to send the same string as a POST
    request?

  • ZeldorBlat

    #2
    Re: how does one send a large string as a POST to another web page?


    lawrence k wrote:[color=blue]
    > If I've a big string and I want to send it to another web page as a GET
    > request, I just use file(). I've done this often.
    >
    > But what command do I use when I want to send the same string as a POST
    > request?[/color]

    <http://www.php.net/curl>

    Comment

    • Chung Leong

      #3
      Re: how does one send a large string as a POST to another web page?


      lawrence k wrote:[color=blue]
      > If I've a big string and I want to send it to another web page as a GET
      > request, I just use file(). I've done this often.
      >
      > But what command do I use when I want to send the same string as a POST
      > request?[/color]

      See http://fi.php.net/stream-context-create/.

      Comment

      • NC

        #4
        Re: how does one send a large string as a POST to another web page?

        lawrence k wrote:[color=blue]
        >
        > If I've a big string and I want to send it to another web page as a
        > GET request, I just use file(). I've done this often.
        >
        > But what command do I use when I want to send the same string
        > as a POST request?[/color]

        You just send a POST request:

        $content = '';
        $flag = false;
        $post_query = 'a=1&b=2'; // name-value pairs
        $post_query = urlencode($post _query) . "\r\n";
        $host = 'www.somehost.c om';
        $path = 'path/to/some/script.php';
        $fp = fsockopen($host , '80');
        if ($fp) {
        fputs($fp, "POST $path HTTP/1.0\r\n");
        fputs($fp, "Host: $host\r\n");
        fputs($fp, "Content-length: ". strlen($post_qu ery) ."\r\n\r\n") ;
        fputs($fp, $post_query);
        while (!feof($fp)) {
        $line = fgets($fp, 10240);
        if ($flag) {
        $content .= $line;
        } else {
        $headers .= $line;
        if (strlen(trim($l ine)) == 0) {
        $flag = true;
        }
        }
        }
        fclose($fp);
        }

        Now $headers contains HTTP headers returned by the remote server, while
        $content contains the body of the response (the document you are trying
        to retrieve).

        Cheers,
        NC

        Comment

        • d

          #5
          Re: how does one send a large string as a POST to another web page?

          "ZeldorBlat " <zeldorblat@gma il.com> wrote in message
          news:1143579273 .137001.105190@ g10g2000cwb.goo glegroups.com.. .[color=blue]
          >
          > lawrence k wrote:[color=green]
          >> If I've a big string and I want to send it to another web page as a GET
          >> request, I just use file(). I've done this often.
          >>
          >> But what command do I use when I want to send the same string as a POST
          >> request?[/color]
          >
          > <http://www.php.net/curl>
          >[/color]

          That's massive overkill for just sending a text string via POST...
          fsockopen() is more than enough :)


          Comment

          Working...