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
Return to the default flat view Create a new topic Submit Reply
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:
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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
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 Nov 29 22:42:37 GMT 2024

Total time taken to generate the page: 0.04343 seconds