Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

david001's avatar

Failed to connect to somedomain.com port 80: Connection refused

I'm trying to set an API for online payment process.According to their documentation i should have like this in url http://localhost:8000/shopping/success/45?oid=XYZ-1234&amt=330&refId=0006QHT

i mean, oid="something"&amt="something"&refId="something"

i got like this in browser. But i got message like this on doing die()at end of code :

Failed to connect to dev.esewa.com.np port 80: Connection refused

I want to know what the message suggesting me .is there anything wrong,How can i solve this error

here is my code

       $site_url = 'http://somedomain.com/public';
        $esewa_url = 'http://dev.esewa.com.np/epay/main';
        $esewa_verfication_url = 'http://dev.esewa.com.np/epay/transrec';
        $merchant_id = "xxxxxx";

        //create array of data to be posted
       // dd($_REQUEST['oid']);
        $post_data['amt'] = $_REQUEST['amt'];
        $post_data['scd'] = $merchant_id;
        $post_data['pid'] = $_REQUEST['oid'];
        $post_data['rid'] = $_REQUEST['refId'];

        //traverse array and prepare data for posting (key1=value1)
        foreach ($post_data as $key => $value) {
        $post_items[] = $key . '=' . $value;
        }

        //create the final string to be posted using implode()
        $post_string = implode('&', $post_items);

       // dd($post_string);

        //create cURL connection
        $curl_connection =
            curl_init($esewa_verfication_url);

       //dd($curl_connection);
        //set options
        curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
        curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
        curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

        //set data to be posted
        curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

        //perform our request
        $result = curl_exec($curl_connection);


        if($result === FALSE) {
          die(curl_error($curl_connection));
//here i go message like this:Failed to connect to dev.esewa.com.np port 80: Connection refused
        }

        //close the connection
        curl_close($curl_connection);


        $verification_response  = strtoupper( trim( strip_tags( $result ) ) ) ;

        if('SUCCESS' == $verification_response){
        echo '<h2><strong>SUCCESS:</strong> Transaction is successful !!!</h2>';
    
        return Redirect::to('/');
        }
        else{
        echo '<h2><strong>ERROR:</strong> Transaction could not be verified</h2>';
            
                return Redirect::to('/');


        }
0 likes
2 replies
Duffleman's avatar

There are q uite a few reasons why cURL would not connect to your host. My immediate line of testing would be to drop laravel and curl totally and ensure you can access dev.esewa.com.np in a browser. I would use a tool such as Postman (Chrome app), and run some tests to ensure you can make contact outside of the program.

If you cannot connect, then there is a problem with the connection, perhaps the domain, or host itself cannot be reached.

If you can connect, then may I suggest running curl through an internal proxy (Charles for Mac, or Fiddler for Windows), and seeing where your connection fails, the inspector features of both programs may give you some great diagnostics as to why no connection can be made.

You currently have your timeout set to 30 seconds, does the program take up all 30 seconds before returning with the error?


Side note, you may want to consider using the http_build_query() function provided by PHP to build your $post_string up. http://php.net/manual/en/function.http-build-query.php

1 like
dakshhmehta's avatar

Recently, I have faced the same issue and it looks like that the endpoints hosting provider have blacklisted my server's IP from which my client is sending a request.

So, I tried deploying to another server of mine and error is gone. Same I tried in localhost, and no error.

So, I assume nothing much you could do if an error is persistent only when you send the request through Laravel.

Please or to participate in this conversation.