2

I have a weird problem with the new twitter api. I followed the very good answer from this question to create a search in twitter and used the TwitterAPIExchange.php from here.

Everything works fine as long as I am directly calling it from my server with CURL. But in the live environment I have to use a proxy with Basic Authentication.

All I've done is add the proxy authentication to the performRequest function:

if(defined('WP_PROXY_HOST') && defined('WP_PROXY_PORT') && defined('WP_PROXY_USERNAME') && defined('WP_PROXY_PASSWORD'))
{
  $options[CURLOPT_HTTPPROXYTUNNEL] = 1;
  $options[CURLOPT_PROXYAUTH] = CURLAUTH_BASIC;
  $options[CURLOPT_PROXY] = WP_PROXY_HOST . ':' . WP_PROXY_PORT;
  $options[CURLOPT_PROXYPORT] = WP_PROXY_PORT;
  $options[CURLOPT_PROXYUSERPWD] = WP_PROXY_USERNAME . ':' . WP_PROXY_PASSWORD;
}

Without the proxy I get a JSON response. But with the proxy I get:

HTTP/1.1 200 Connection established HTTP/1.1 400 Bad Request content-type: application/json; charset=utf-8 date: Fri, 20 Dec 2013 09:22:59 UTC server: tfe strict-transport-security: max-age=631138519 content-length: 61 Proxy-Connection: Keep-Alive Connection: Keep-Alive Set-Cookie: guest_id=v1%3A138753137985809686; Domain=.twitter.com; Path=/; Expires=Sun, 20-Dec-2015 09:22:59 UTC Age: 0 {"errors":[{"message":"Bad Authentication data","code":215}]}

I've tried to simulate a proxy in my local environment with Charles Proxy, and it worked.

I'm assuming the proxy is either not sending the Authentication Header, or is changing data somehow.

Anybody with a clue....

EDIT: Using the HTTP API works but HTTPS fails. I've tried CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST set to FALSE but the twitter SSL is valid so this is not recommended

Community
  • 1
  • 1
spankmaster79
  • 21,555
  • 10
  • 42
  • 73

1 Answers1

0

Is your proxy response caches or is the date in the proxy response old because you did perform the API call on the 20th december?

If it is cached maybe your proxy is having a cached reply from an actual invalid request?