SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can I get HTTP body, HELP me!

    I have to make a script myscript.php that is called this way:

    POST /myscript.php HTTP/1.1
    Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*
    Accept-Language: bg
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)
    Host: 192.168.0.1:8000
    Content-Type: text/xml
    Connection: Keep-Ali

    <xml>
    <node1>node1 value</node1>
    </xml>


    I need to get and parse the body of the request.

    In short, I need to get this

    <xml>
    <node1>node1 value</node1>
    </xml>

    How could I get this content in PHP?
    How could I get the body of the request?

    Thank you.

  2. #2
    SitePoint Addict pointbeing's Avatar
    Join Date
    Jun 2004
    Location
    London, UK
    Posts
    227
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you have it enabled, you can try to access $_SERVER['HTTP_RAW_POST_DATA'], or in PHP5 you have file_get_contents('php://input');

    Neither of those are guaranteed to work in all situations, but there's two things to try, at least - hth

  3. #3
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks

    There is the solution that is working:

    $ph = fopen("php://input", "rb");
    while (!feof($ph))
    {
    $post .= fread($ph, 4096);
    }
    fclose($ph);

    Thaks for the help!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •