fsockopen

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thomas werth

    fsockopen

    hi i am struggling with this... maybe someone else had a similar problem
    before...

    i have to pass 2 variables: (language) and an (xml query string) using http
    POST to a search engine. doing this with a normal html form, the seach
    engine returns a nice xml response. yet, when passing the POST vars using
    the script below, the server does not give any response, it keeps loading
    the page.
    the script for posting the variables does work since i tested it, i just
    dont know what to look for anymore...

    html form:
    <form name=SeekEngine method=Post
    action="http://www.suedtirol.i nfo/XmlApi/Demo/SeekEngine.get? xx=1">
    <input type=hidden name=Language value=IT>
    <textarea style="font-size:12px" name="XmlParame ters" value="" rows=10
    cols=135>
    <Parameters>
    <Group Value="Bike" />
    <HotelComfort Value="A.001.00 4.000.000;A.001 .003.000.000;" />
    <HotelComfort Value="A.012.02 0.015.000;A.012 .020.020.000;" />
    <Stay CheckIn="12/1/2003" Days="2" Board="4" Bookable="0" />
    <Room Qty="1" Persons="2" Type="1" />
    <HierarchyID Value=""/>
    </Parameters>
    </textarea>
    <input type=button onclick="SendDa ta(form);" name=sEEKeNGINE
    value="Engine.G et">
    </form>

    php fct:

    <?php
    //############### ############### ############### ############### ##############
    ############### ########
    //SIMULATES A (HTTP POST) FORM SUBMISSION
    //www.zend.com/zend/spotlight/mimocsumissions .php
    //takes 2 parameters: associative array containing data to be sent to
    server, DNS or IP of server
    //returns $result array with lines of response
    function post_it($datast ream, $url)
    //############### ############### ############### ############### ##############
    ############### ########
    {
    //replace http:// with the empty string, get host, get resource
    $url = preg_replace("@ ^http://@i", "", $url);
    $host = substr($url, 0, strpos($url, "/"));
    $uri = strstr($url, "/"); // kontakt/formular.php

    //construct request body: vars and their values
    $reqbody ="";
    foreach ($datastream as $key => $val)
    {
    if (!empty($reqbod y))
    $reqbody .= "&";
    $reqbody .= $key."=".urlenc ode($val);
    }

    //construct post request to be sent to server, include size of reqbody
    $contentlength = strlen($reqbody );
    $reqheader = "POST $uri HTTP/1.1 \r\n";
    $reqheader .= "Host: $host\n";
    $reqheader .= "User-Agent: PostIt\r\n";
    $reqheader .= "Content-Type: application/x-www-form-urlencoded\r\n" ;
    $reqheader .= "Content-Length: $contentlength\ r\n\r\n";
    $reqheader .= "$reqbody\r \n";

    //connect to server, send POST request, read result, close socket
    $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;
    }
    //############### ############### ############### ############### ##############
    ############### ########
    ?>

    any help is very appreciated : )
    tom


  • Niall Kavanagh

    #2
    Re: fsockopen

    thomas werth <werth@cyber-ideas.com> wrote:[color=blue]
    > hi i am struggling with this... maybe someone else had a similar problem
    > before...[/color]
    [color=blue]
    > i have to pass 2 variables: (language) and an (xml query string) using http
    > POST to a search engine. doing this with a normal html form, the seach[/color]
    [color=blue]
    > <input type=button onclick="SendDa ta(form);" name=sEEKeNGINE
    > value="Engine.G et">[/color]

    Offtopic, but I'm guessing the page "refreshes" because you're
    not passing the sEEKeNGINE value when you POST.

    --
    niall

    Comment

    Working...