Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

curl calls not working behind proxy and no curl proxy support #64

Open
woutersf opened this issue Sep 4, 2014 · 3 comments · May be fixed by #258
Open

curl calls not working behind proxy and no curl proxy support #64

woutersf opened this issue Sep 4, 2014 · 3 comments · May be fixed by #258

Comments

@woutersf
Copy link

woutersf commented Sep 4, 2014

We have this issue.
It does not seem to be supported in this class...
Is this the code to be added to make this work?

variables:

  /**
   * Proxy server
   * @var unknown
   */
  private $proxy_server = false;

  /**
   * Proxy username
   * @var unknown
   */
  private $proxy_server_user = false;

  /**
   * Proxy password
   * @var unknown
   */
  private $proxy_server_pass = '';

The code to be added at the curl calls:

 $ch = curl_init();
    if ($this->proxy_server) {
      curl_setopt($ch, CURLOPT_PROXY, $this->proxy_server);
      if ($this->proxy_server_user) {
        $proxyauth = $this->proxy_server_user . ':' . $this->proxy_server_pass;
        curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
      }
    }
    curl_setopt($ch, CURLOPT_URL, $apiCall);

getters & setters

  /**
   * get the proxy server
   * @return unknown
   */
  public function getProxyServer() {
    return $this->proxy_server;
  }

  /**
   * set the proxy server
   * @param unknown $server
   */
  public function setProxyServer($server) {
    $this->proxy_server = $server;
  }

  /**
   * get the proxy server Username
   * @return unknown
   */
  public function getProxyUser(){
    return $this->proxy_server_user;
  }

  /**
   * get the proxy server password
   * @return unknown
   */
  public function getProxyPass(){
    return $this->proxy_server_pass;
  }

  /**
   * set the proxy username
   * @param unknown $user
   */
  public function setProxyUser($user){
    $this->proxy_server_user = $user;
  }

  /**
   * set the proxy password
   * @param unknown $pass
   */
  public function setProxyPass($pass){
    $this->proxy_server_pass = $pass;
  }
@woutersf
Copy link
Author

woutersf commented Sep 4, 2014

Also added proxy port

  /**
   * Proxy port
   * @var unknown
   */
  private $proxy_port = '';

...

if ($this->proxy_server) {
      curl_setopt($ch, CURLOPT_PROXY, $this->proxy_server);
      curl_setopt($ch, CURLOPT_PROXYPORT,  $this->proxy_port);
      if ($this->proxy_server_user) {
        $proxyauth = $this->proxy_server_user . ':' . $this->proxy_server_pass;
        curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
      }
    }

...
  /**
   * Get proxy port
   * @return unknown
   */
  public function getProxyPort() {
    return $this->proxy_port;
  }

/**
   * Set the proxy port
   * @param unknown $port
   */
  public function setProxyPort($port){
    $this->proxy_port = $port;
  }

@hannesbochmann
Copy link

hannesbochmann commented Feb 13, 2019

Maybe I can shed some light on this problem as we face a similar one. When the server is behind a proxy all curl requests which return headers will have extra headers of the proxy. those extra headers are separated by two line breaks. And that's the actual problem. As the API class explodes the API response by two line breaks and uses only the first two occurrences there won't be the header data in the first part and the JSON in the second with a proxy. It would be the header data of the proxy in the first part and the header data of instagram in the second. The JSON would be third

The response with a proxy can look like this:

HTTP/1.1 200 Connection established

HTTP/1.1 302 Found
Content-Type: text/html; charset=utf-8
Location: https://www.instagram.com/
...

{"pagination": {"next_max_id": ..

Without proxy it would be:

HTTP/1.1 302 Found
Content-Type: text/html; charset=utf-8
Location: https://www.instagram.com/
...

{"pagination": {"next_max_id": ..

Maybe it's better to not use the first two parts of the response but the last two. This should always be the last header data and the JSON data no matter on many proxies are in the way.

I'm willing to create a pull request if there is a chance that you accept it.

hannesbochmann added a commit to hannesbochmann/Instagram-PHP-API that referenced this issue Apr 8, 2019
@hannesbochmann hannesbochmann linked a pull request Apr 8, 2019 that will close this issue
hannesbochmann added a commit to hannesbochmann/Instagram-PHP-API that referenced this issue Apr 9, 2019
@hannesbochmann
Copy link

Ping. Is there any chance that my pull request will get merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants