I'm trying to fopen a URL as follows:
$fp = fopen($work_string, "r");
The fopen is failing wih a 'unable to open stream' HTTP 400 - Bad Request
If I copy the contents of $work_string and paste it into Internet Explorer - it works I get the XML response back correctly.
If I change $work_string to something simple such as http://www.microsoft.com with no additional parameters, then the fopen works fine.
The contents of $work_string are as follows:
$work_string = 'http://testing.shippingapis.com/Shippin ... ateRequest USERID="myuserid" PASSWORD="mypassword"><Package ID="0"><Service>EXPRESS</Service><ZipOrigination>20770</ZipOrigination><ZipDestination>20852</ZipDestination><Pounds>10</Pounds><Ounces>0</Ounces><Container>None</Container><Size>REGULAR</Size><Machinable></Machinable></Package></RateRequest>';
I'm using Apache 2.0.48 and PHP 4.3.4 in Windows XP.
I've temporarily changed the code to use fsockopen and got it to work - but I really want to get this fopen to work - or at least an understanding why it is failing.
Thanks
David
Problem with fopen opening a URL
Moderator: General Moderators
I have a feeling that you're going to need to fsockopen() to 'http://testing.shippingapis.com/ShippingAPITest.dll', port 80, and then send a HTTP GET request using fputs() which will prompt the server for the output that you want.
The reason, I think, why fopen is failing is because what you are trying to do is get an XML stream. The fact that it is XML is irrelevant, but fopen() is generally for file handling with static files and doing stuff with their content, where as fsockopen() is for interacting with a file or resource, and making it produce stuff on command. And strictly speaking, fopen()ing to a .dll on a webserver is not a static file by any means.
I'm afraid that I can't product any code, but I hope i'm on the right tracks and nudging you in the right direction.
I think you'll be needing feof(), fputs() and as you already know, fsockopen().
Hope this helps.
The reason, I think, why fopen is failing is because what you are trying to do is get an XML stream. The fact that it is XML is irrelevant, but fopen() is generally for file handling with static files and doing stuff with their content, where as fsockopen() is for interacting with a file or resource, and making it produce stuff on command. And strictly speaking, fopen()ing to a .dll on a webserver is not a static file by any means.
I'm afraid that I can't product any code, but I hope i'm on the right tracks and nudging you in the right direction.
I think you'll be needing feof(), fputs() and as you already know, fsockopen().
Hope this helps.
Yes, I think you may be right..... As I mentioned in my post, I did change the code to use fsockopen and got it to work OK.
It was more the fact that the code came to me with fopen along with an assurance that it worked! ... and it 'must be me'.... that had me concerned.
Thanks for the reply.
From an exiled Mancunian. (blue not red)..
David
It was more the fact that the code came to me with fopen along with an assurance that it worked! ... and it 'must be me'.... that had me concerned.
Thanks for the reply.
From an exiled Mancunian. (blue not red)..
David