Results 1 to 7 of 7

Thread: Received HTTP code 403 from proxy after CONNECT

  1. #1
    Guest

    Default Received HTTP code 403 from proxy after CONNECT

    Hi.
    I am building a BOT for Facebook messenger. Two weeks ago it worked like a charm, but, since February 14 I am having problems with CURL.

    With php 5.6 enabled I get the error "Received HTTP code 403 from proxy after CONNECT" (on Messenger).
    This error disappears with php 5.4, but I cannot use this version since it causes troubles with the acquisition of users' information from Facebook.

    Could you tell me how to fix it?

    Thanks

  2. #2
    karl94 is offline AlterVista Staff
    Join Date
    Jan 2015
    Posts
    573

    Default

    Quote Originally Posted by rmabotprova View Post
    Could you tell me how to fix it?
    If you provide the code you're using we can give a look to it.

  3. #3
    Guest

    Default

    Thanks!

    This is an excerpt of the callback page that only works with php 5.6.

    When I enable php 5.4, I get the error "Facebook SDK returned an error: No URL set!". I commented the line header("location: https://www.messenger.com/t/..."); for debugging reasons.

    Code:
    <?php
    	$fb = new Facebook\Facebook([
    	  'app_id' => '...',
    	  'app_secret' => '...',
    	  'default_graph_version' => 'v2.6',
    	  ]);
    	  //header("location: https://www.messenger.com/t/...");
    }
    
    $helper = $fb->getRedirectLoginHelper();  
      
    try {  
      $accessToken = $helper->getAccessToken();  
    } catch(Facebook\Exceptions\FacebookResponseException $e) {  
    
      echo 'Graph returned an error: ' . $e->getMessage();  
      exit;  
    } catch(Facebook\Exceptions\FacebookSDKException $e) {  
    
      echo 'Facebook SDK returned an error: ' . $e->getMessage();  
      exit;  
    }  
    ?>
    Then, the callback page points to "https://www.messenger.com/t/..." messenger page, whose behavior is specified in the file webhook.php (below you have an excerpt)

    Code:
    <?php
    ini_set("allow_url_fopen", 1);
    require ("config.php");
    session_start();
    $verify_token = $_REQUEST['hub_verify_token'];
    
    if ($verify_token === '...') {
      echo $challenge;
    }
    else{
      $json2 = fixJson (file_get_contents('php://input'));
      $input = json_decode($json2, true);
    
      $sender = $input['entry'][0]['messaging'][0]['sender']['id'];
      $message = $input['entry'][0]['messaging'][0]['message']['text'];
      $postback = $input['entry'][0]['messaging'][0]['postback']['payload'];
    
      $pagid = '...';
    
      if ($sender != $pagid && ($postback=="Start" || $message == "test") ){
    
        $ch = curl_init();
        $url = 'https://graph.facebook.com/v2.6/'.$sender.'?fields=first_name,last_name&access_token='.ACCESS_TOKEN;
    
        curl_setopt( $ch, CURLOPT_URL, $url );
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    
        $resp = curl_exec( $ch );
        $info = curl_getinfo($ch);
    
        writeLog("curl  ".$resp. " sender ".$sender. " url ".$url." info: ".$info['http_code']);
        writeLog("curl error ".curl_error($ch));
    
        curl_close($ch);
        }
    }
    
    function writeLog ($text) {
      // function that writes the log file
    }
    
    function fixJson ($json) {
        return (preg_replace ('/:\s?(\d{14,})/', ': "${1}"', $json));
    }
    ?>
    The curl call only works if I enable php 5.4. With php 5.6 curl_error() returns "Received HTTP code 403 from proxy after CONNECT".

    Maybe I only need to change some configurations in php 5.6. One day it worked and the following day no more (with no changes in the code).

    Thank you for your support

  4. #4
    Guest

    Default

    Hi, could you please tell me if the code I provided you is sufficient, or if you need additional information?

    Thanks

  5. #5
    karl94 is offline AlterVista Staff
    Join Date
    Jan 2015
    Posts
    573

    Default

    You just need to disable and re-enable CloudFlare from the AlterVista control panel.

  6. #6
    Guest

    Default

    Thanks, I will try it!

  7. #7
    Guest

    Default

    Just to let you - and the other users which could have a similar problem - know, disabling and re-enabling CloudFare and https worked :-)

    Thanks for the awesome support!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

SEO by vBSEO