Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

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

Avatar of claudioimai
claudioimaiFlag for Japan asked on
Web Servers
1 Comment1 Solution1818 ViewsLast Modified:

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)
                debug_var ($resp, "fsockopen: ".date("Y-m-d G:i:s"),true);
        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.

Avatar of Sam Panwar
Sam PanwarFlag of India imageSr. Server Administrator

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answers