Jump to content

Recommended Posts

Hi, I'm kind of stuck.

 

I'm trying to submit a form to another URL from my own web server, then retrieve the result by getting the page content.

 

But it doesn't seems to work.

 

The page I'm trying to get content is this

http://epoly.tp.edu.sg/tpapp/isistt/TTServlet

 

Use my admin for testing,

0800520I

 

It's either you search by admin or the person name.

 

Anyone has any idea?

Thanks for the reply!

 

But I couldn't get it to work,

 

this is what my friend had come out with

 

<?php

function PostRequest($url, $referer, $_data) 
{

    // convert variables array to string:
    $data = array();    
    while(list($n,$v) = each($_data)){
        $data[] = "$n=$v";
    }    
    $data = implode('&', $data);
    // format --> test1=a&test2=b etc.

    // parse the given URL
    $url = parse_url($url);
    if ($url['scheme'] != 'http') { 
        die('Only HTTP request are supported !');
    }

    // extract host and path:
    $host = $url['host'];
    $path = $url['path'];

    // open a socket connection on port 80
    $fp = fsockopen($host, 80);

    // send the request headers:
    fputs($fp, "POST $path HTTP/1.1\r\n");
    fputs($fp, "Host: $host\r\n");
    fputs($fp, "Referer: $referer\r\n");
//fputs($fp, "Expires: Mon, 26 Jul 2010 05:00:00 GMT\r\n");
    fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
    fputs($fp, "Content-length: ". strlen($data) ."\r\n");
    fputs($fp, "Connection: close\r\n\r\n");
    fputs($fp, $data);

    $result = ''; 
    while(!feof($fp)) {
        // receive the results of the request
        $result .= fgets($fp, 128);
    }

    // close the socket connection:
    fclose($fp);

    // split the result header from the content
    $result = explode("\r\n\r\n", $result, 2);

    $header = isset($result[0]) ? $result[0] : '';
    $content = isset($result[1]) ? $result[1] : '';

    // return as array:
    return array($header, $content);
}



$data = array(
    'txtModule' => 'StudentSearch',
    'txtSelStudentID' => '0800520I',
    'cboSearch' => 'Student',
'txtAction' => 'TTServlet',
'txtAdmNo' => '0800520I');

// send a request to example.com (referer = jonasjohn.de)
list($header, $content) = PostRequest("http://epoly.tp.edu.sg/tpapp/isistt/","http://localhost:80",$data);

// print the result of the whole request:
print $content;

// print $header; --> prints the headers
//print $header;
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.