FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Intercepting a HTTP request
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Intercepting a HTTP request [message #171649] Fri, 14 January 2011 08:18 Go to next message
Michaelprem123 is currently offline  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 #171650 is a reply to message #171649] Fri, 14 January 2011 08:32 Go to previous messageGo to next message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 14-01-11 09:18, Michaelprem123 wrote:
> How do I intercept the HTTP request

http://www.google.com/search?q=How+do+I+intercept+the+HTTP+request

--
Luuk
Re: Intercepting a HTTP request [message #171651 is a reply to message #171649] Fri, 14 January 2011 08:34 Go to previous messageGo to next message
alvaro.NOSPAMTHANX is currently offline  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 Go to previous message
Thomas 'PointedEars'  is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: ANNOUNCE: NHI1-0.11, PLMK-2.0 und libmsgque-5.0
Next Topic: php xml DOM/xpath how to reference child nodes by name within foreach loop?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Sep 27 21:27:33 GMT 2024

Total time taken to generate the page: 0.02653 seconds