Jump to content

HTTP request not working


ttocskcaj

Recommended Posts

I have this code:

error_reporting(E_ALL);
        $post = array();
        $post['user'] = "ttocskcaj";
        $post['group'] = "Mod";
        $ret = '';
        $postdata_str = "user=" . $post['user'] . "&group=" . $post['group'];
        if (($fp = @fsockopen("www.secret.com", 8101, $errno, $errstr)) == false)
            die("Error $errno: $errstr\n");
        fputs($fp, "POST /permissions-proceed HTTP/1.0\r\n");
        fputs($fp, "Host: www.secret.com:8101");
        fputs($fp, "User-Agent: HTTPTool/1.0\r\n");
        fputs($fp, "Content-Length: 256\r\n\r\n");
        fputs($fp, "$postdata_str");
        while (!feof($fp)) {
            // receive the results of the request
            echo "<pre>".fgets($fp, 128)."</pre>";
        }
        fclose($fp);

Which is supposed to send a username and a group to a python script where the user is put into that group.

It's not working though.

I just want to check if everything is alright on this end, before trying to find what's wrong in the python.

Link to comment
https://forums.phpfreaks.com/topic/239724-http-request-not-working/
Share on other sites

Not sure what I was doing wrong, but I changed it to use cURL and now it works fine :s

 

$survival_curl = curl_init();
curl_setopt($survival_curl, CURLOPT_URL, "http://www.secret.com");
curl_setopt($survival_curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($survival_curl, CURLOPT_POST, true);
curl_setopt($survival_curl, CURLOPT_POSTFIELDS, $data);
$output_survival = curl_exec($survival_curl);
$info_survival = curl_getinfo($survival_curl);
curl_close($survival_curl);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.