Intercepting a HTTP request [message #171649] |
Fri, 14 January 2011 08:18 |
Michaelprem123
Messages: 1 Registered: January 2011
Karma: 0
|
Junior Member |
|
|
Hello!
I am using PHP, programming a mashup against MBrainz and last.fm (it
is a teaching related exercise)
I am trying to use a DOMDocument::load to send an API method on a url
parameter, but get an error back.
"HTTP request failed! HTTP/1.0 400 Bad Request"
The same url reacts perfectly when sent on an address line of a
browser. Seems like a User Agent related problem, but setting the user
agent of my PHP script did not help.
How do I intercept the HTTP request that php DOMDocument sends to the
last.fm server to get a closer look at whats going on?
Thanks
Michael
|
|
|
|
Re: Intercepting a HTTP request [message #171651 is a reply to message #171649] |
Fri, 14 January 2011 08:34 |
alvaro.NOSPAMTHANX
Messages: 277 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
El 14/01/2011 9:18, Michaelprem123 escribió/wrote:
> I am using PHP, programming a mashup against MBrainz and last.fm (it
> is a teaching related exercise)
>
> I am trying to use a DOMDocument::load to send an API method on a url
> parameter, but get an error back.
> "HTTP request failed! HTTP/1.0 400 Bad Request"
>
> The same url reacts perfectly when sent on an address line of a
> browser. Seems like a User Agent related problem, but setting the user
> agent of my PHP script did not help.
>
> How do I intercept the HTTP request that php DOMDocument sends to the
> last.fm server to get a closer look at whats going on?
The available tools depend on your operating system (which don't say).
For Windows, you have Wireshark.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
|
|
|
Re: Intercepting a HTTP request [message #171665 is a reply to message #171649] |
Fri, 14 January 2011 23:26 |
Thomas 'PointedEars'
Messages: 701 Registered: October 2010
Karma: 0
|
Senior Member |
|
|
Michaelprem123 wrote:
> I am using PHP, programming a mashup against MBrainz and last.fm (it
> is a teaching related exercise)
>
> I am trying to use a DOMDocument::load to send an API method on a url
> parameter, but get an error back.
> "HTTP request failed! HTTP/1.0 400 Bad Request"
The reason for that might also be that a POST request is expected, or that a
parameter is missing.
> The same url reacts perfectly when sent on an address line of a
> browser. Seems like a User Agent related problem, but setting the user
> agent of my PHP script did not help.
>
> How do I intercept the HTTP request that php DOMDocument sends to the
> last.fm server to get a closer look at whats going on?
I would use the netcat[tm] to listen at a free local port (like 1337) and
direct DOMDocument::load() to localhost at that port:
$ nc -lp 1337 &
[1] 23953
$ php -r '$x = new DOMDocument(); $x->load("http://localhost:1337/");'
GET / HTTP/1.0
Host: localhost:1337
[1]+ Stopped nc -lp 1337
^C
<http://php.net/manual/en/domdocument.load.php#91384> shows how to set the
User-Agent header field for the DOMDocument HTTP request (as your script's
header() has nothing to do with that).
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
|
|
|