Requesting file via PHP fails, but succeeds in Python


The URL in question :

When accessed in a browser, it will correctly download a file (which is an XML document). I wanted to get the file in php, and simply display its contents on a page.

$contents = file_get_contents("");

The above is what I've tried using (as far as I know, the page does not expect any headers). I get a 500 HTTP error. However, in Python, the following code works and I receive the file.

r = requests.get("")

I'm confused as to what the distinction is between how these two requests are sent. I am almost 100% it is not a header problem. I've also tried the cURL library in PHP to no avail. Nothing I've tried in PHP seems to succeed with the URL (with any valid id parameter); but Python is able to bring success nonchalantly.

Any insight as to why this issue may be happening would be great.

EDIT : I have already tried copying Python's headers into my PHP request.

EDIT2 : It also appears that there are two requests happening upon navigating to the link.




Is this on a linux/mac host by chance? If so you could use ngrep to see the differences on the request themselves on the wire. Something like the following should work

ngrep -t '^(GET) ' 'src host and tcp and dst port 80'

EDIT - The problem is that your server is responding with a 302 and the PHP library is not following it automatically. Cheers!

People are also looking for solutions to the problem: php - How can I receive values using POST method in laravel?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.