Link to home
Start Free TrialLog in
Avatar of claudioimai
claudioimaiFlag for Japan

asked on

fsockopen returns Bad Request (Invalid hostname) in one server, but works fine in others

Hello.

I have a paymento module developed for oscommerce, working well in several servers, but got a problem in a specific setup:

1. I can't use cURL, as it is not avaiolable in this server;
2. using fsockopen to access a host, the script connects, but only in http (non secure) mode;
3. Passing the header as:
 } elseif ($fsocket == true) {
    $Cabecalho  = "POST /Security/NPI/Default.aspx HTTP/1.1\r\n";
    $Cabecalho .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $Cabecalho .= "Content-Length: " . strlen($BRpay) . "\r\n\r\n";

 
    if ($fp || $errno>0){
        fputs ($fp, $Cabecalho . $BRpay);
        $confirma = false;
        $resp = '';
        while (!feof($fp)){
            $res = @fgets ($fp, 1024);
            $resp .= $res;
           
            if (strcmp ($res, "VERIFICADO") == 0)
            {
                $confirma=true;
                debug_var ($resp, "fsockopen: ".date("Y-m-d G:i:s"),true);
                break;
            }
        }
        fclose ($fp);
    } else{
        echo "$errstr ($errno)<br />\n";
             debug_var ($errstr.'('.$errno.')', "erro em fsockopen:: ".date("Y-m-d G:i:s"),true);
        // ERRO HTTP
      }
  }

I have the following answer:

HTTP/1.1 400 Bad Request
Content-Type: text/html
Date: Sat, 02 Dec 2006 18:18:27 GMT
Connection: close
Content-Length: 39

<h1>Bad Request (Invalid Hostname)</h1>

The string $BRpay contains the data to be validated in the server. The same data works in my test server.

This scripts works well in many environments, but in this specific one, it doesn't:
* PHP 4.4.2
* Linux Server
* MySQL 4.1.2
* Server protocol HTTP/1.1

I hope someone can help me, as this problem prevents my client to use this payment mode, and I need to fix it ASAP.

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Sam Panwar
Sam Panwar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial