WordPress / Requests

Requests for PHP is a humble HTTP request library. It simplifies how you interact with other sites and takes away all your worries.
https://requests.ryanmccue.info/
Other
3.57k stars 498 forks source link

Works in Localhost does not work in webserver #235

Open sriducati opened 8 years ago

sriducati commented 8 years ago

I am trying to fetch contents from

https://some.com/suggestions.php?q=kann

include('./Request/library/Requests.php');
Requests::register_autoloader();
$request = Requests::get('https://some.com/suggestions.php?q=kann',array('Accept' => 'application/json'));
echo json_encode($request->body);

Above code works fine when we run on localHost But I get

"500 Internal server error

PhP Error Shows

`

Fatal error: Uncaught exception 'Requests_Exception' with message 'cURL error 28: Operation timed out after 10000 milliseconds with 0 bytes received' in /home/admin/domains/domain.com/public_html/Request/library/Requests/Transport/cURL.php:277 Stack trace: #0 /home/admin/domains/domain.com/public_html/Request/library/Requests/Transport/cURL.php(120): Requests_Transport_cURL->process_response(false, Array) #1 /home/admin/domains/domain.com/public_html/Request/library/Requests.php(317): Requests_Transport_cURL->request('https://some.com...', Array, NULL, Array) #2 /home/admin/domains/domain.com/public_html/Request/library/Requests.php(194): Requests::request('https://some.com...', Array, NULL, 'GET', Array) #3 /home/admin/domains/domain.com/public_html/Request/examples/get.php(14): Requests::get('https://some.com...', Array) #4 {main} thrown in /home/admin/domains/domain.com/public_html/Request/library/Requests/Transport/cURL.php on line 277

`

when run on webserver, is there any way to fix this?

ramesh-tr commented 8 years ago

Are you running your code behind a firewall or proxy on the web server?

allanlaal commented 7 years ago

the remote server is probably using a newer TLS version than your webservers cURL supports (i.e. TLS v1.2).

If you are unable to update the webservers cURL, then set Requests_Transport_fsockopen as the preferred transport method with Requests::add_transport.

include('./Request/library/Requests.php');
Requests::register_autoloader();
Requests::add_transport('Requests_Transport_fsockopen')
$request = Requests::get('https://some.com/suggestions.php?q=kann',array('Accept' => 'application/json'));
echo json_encode($request->body);

Sadly overriding the preferred transport method does not work in this library (yet), so I forked my own and fixed Requests::add_transport() there: https://github.com/allanlaal/Requests

I've iniated a pull request too: https://github.com/rmccue/Requests/pull/258