 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
griffmcc
Joined: 05 Mar 2009 Posts: 7
|
Posted: Tue Sep 22, 2009 11:59 pm Post subject: Can HTTP_Request2 handle a URL with a query_string? |
|
|
I want to use HTTP_Request2 to read from URLs like:
http://finance.yahoo.com/q?s=SPY
The code works if I leave off the query string "q?s=SPY", but if I include the query string, I get the error: 400 Bad Request.
The problem is not with finance.yahoo.com because I have a python program that reads from the same URLs that are rejected with PHP.
What do I need to do to get HTTP_Request2 to handle the query string?
PHP code with error:
| Code: | <?php
require_once('HTTP/Request2.php');
$r = new HTTP_Request2("http://finance.yahoo.com/q?s=SPY");
// $r = new HTTP_Request2('http://finance.yahoo.com'); THIS WORKS
$r->setMethod(HTTP_REQUEST_METHOD_GET);
$resp = $r->send();
$response_body = $resp->getBody();
print "Body: <br />\n";
print $response_body;
?> |
Python program that works:
| Code: | import urllib
import locale
def GetUrl(url):
try:
sock = urllib.urlopen(url)
html = sock.read()
sock.close()
return html
except:
print "%s is not on yahoo" % url
return
if __name__ == "__main__":
print GetUrl('http://finance.yahoo.com/q?s=SPY')
|
|
|
| Back to top |
|
 |
griffmcc
Joined: 05 Mar 2009 Posts: 7
|
Posted: Thu Sep 24, 2009 10:18 pm Post subject: urlencode() and rawurlencode() didn't help |
|
|
I tried to use urlencode() and rawurlencode() on either the entire URL or just the query string, but nothing worked.
| Code: | $r = new HTTP_Request2("http://finance.yahoo.com/".rawurlencode("q?s=SPY")); // "Method not implemented"
// $r = new HTTP_Request2("http://finance.yahoo.com/".urlencode("q?s=SPY")); // "Method not implemented"
// $r = new HTTP_Request2("http://finance.yahoo.com/".urlencode("q?s='SPY'")); // "Method not implemented"
// $r = new HTTP_Request2(urlencode('http://finance.yahoo.com')); // "thrown in /usr/share/php/HTTP/Request2.php on line 779"
// $r = new HTTP_Request2("http://finance.yahoo.com/q?s='SPY'"); // 400 Bad Request
// $r = new HTTP_Request2('http://finance.yahoo.com/q?s=MXB'); // 400 Bad Request
// $r = new HTTP_Request2('http://finance.yahoo.com'); // WORKS
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|