469,887 Members | 1,903 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,887 developers. It's quick & easy.

fopen question.

Is there a limit to how long a URL can be with fopen? I have a very
long URL as there are lots of things to be passed some variables and
some XML. It seems to get to a certain point and then produce an error
with no details and just cuts it off.

<?php

$url = 'http://test.com/Test.dll?API=test&XML='.
'&lt;FromLastName&gt;FromLast&lt;/FromLastName&gt;'.
'&lt;FromFirm&gt;FromFirm&lt;/FromFirm&gt;'.
'&lt;FromAddress1&gt;FromAddress1&lt;/FromAddress1&gt;'.
'&lt;FromAddress2&gt;6406IvyLane&lt;/FromAddress2&gt;'.
'&lt;FromCity&gt;Greenbelt&lt;/FromCity&gt;'.
'&lt;FromState&gt;MD&lt;/FromState&gt;'.
'&lt;FromZip5&gt;20770&lt;/FromZip5&gt;'.
'&lt;FromZip4&gt;1234&lt;/FromZip4&gt;'.
'&lt;FromPhone&gt;3019187658&lt;/FromPhone&gt;'.
'&lt;ToAddress1&gt;ToAddress1&lt;/ToAddress1&gt;'.
'&lt;ToAddress2&gt;ToAddress2&lt;/ToAddress2&gt;'.
'&lt;ToAddress3&gt;ToAddress3&lt;/ToAddress3&gt;'.
'&lt;ToAddress4&gt;ToAddress4&lt;/ToAddress4&gt;'.
'&lt;ToAddress5&gt;ToAddress5&lt;/ToAddress5&gt;'.
'&lt;ToAddress6&gt;ToAddress6&lt;/ToAddress6&gt;'.
'&lt;ToCountry&gt;France&lt;/ToCountry&gt;'.
'&lt;ToAPOFPOZip5&gt;&lt;/ToAPOFPOZip5&gt;'.
'&lt;ToPhone&gt;&lt;/ToPhone&gt;'.
'&lt;ToFax&gt;&lt;/ToFax&gt;'.
'&lt;ToEmail&gt;&lt;/ToEmail&gt;'.
'&lt;ShippingContents&gt;&lt;ItemDetail&gt;'.
'&lt;Description&gt;Description1&lt;/Description&gt;'.
'&lt;Quantity&gt;1&lt;/Quantity&gt;'.
'&lt;Value&gt;1&lt;/Value&gt;'.
'&lt;NetPounds&gt;5&lt;/NetPounds&gt;'.
'&lt;NetOunces&gt;0&lt;/NetOunces&gt;'.
'&lt;/ItemDetail&gt;&lt;ItemDetail&gt;'.
'&lt;Description&gt;Descripton2&lt;/Description&gt;'.
'&lt;Quantity&gt;5&lt;/Quantity&gt;'.
'&lt;Value&gt;17&lt;/Value&gt;'.
'&lt;NetPounds&gt;2&lt;/NetPounds&gt;'.
'&lt;NetOunces&gt;2&lt;/NetOunces&gt;'.
'&lt;/ItemDetail&gt;&lt;/ShippingContents&gt;'.
'&lt;GrossPounds&gt;7&lt;/GrossPounds&gt;'.
'&lt;GrossOunces&gt;2&lt;/GrossOunces&gt;'.
'&lt;ImageType&gt;GIF&lt;/ImageType&gt;'.
'&lt;ContentType&gt;Gift&lt;/ContentType&gt;'.
'&lt;HSTariffNumber&gt;&lt;/HSTariffNumber&gt;'.
'&lt;CountryOfOrigin&gt;&lt;/CountryOfOrigin&gt;'.
'&lt;CustomerRefNo&gt;&lt;/CustomerRefNo&gt;'.
'&lt;/CustomsCN22CertifyRequest&gt;';

$aurl=fopen($xml,"r");
while (!feof ($aurl, 4096))
$xml .= fgets($aurl);
fclose ($aurl);
?>

Jul 17 '05 #1
3 1891
"theouimets" wrote:
Is there a limit to how long a URL can be with fopen? I have a very
long URL as there are lots of things to be passed some variables and some XML. It seems to get to a certain point and then produce an error with no details and just cuts it off.

snip...
?>


http://ca3.php.net/manual/en/functio...et-timeout.php

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-fopen-ftopict142029.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=474952
Jul 17 '05 #2
th********@hotmail.com wrote:
Is there a limit to how long a URL can be with fopen? I have a very
long URL as there are lots of things to be passed some variables and
some XML. It seems to get to a certain point and then produce an error
with no details and just cuts it off.


With long requests it's almost always better to use the POST method instead
of GET.

Consider the following snippet or use one of the many classes available on
the net:

// Construct the request string
$request = "API=test&XML=" . urlencode("&lt;FormLastName...");

// Open connection
$fp = fsockopen("test.com", 80);

// Send the request
fputs($fp, "POST /Test.dll HTTP/1.0\r\n");
fputs($fp, "Host: test.com\r\n");
fputs($fp, "Content-Length: " . strlen($request) . "\r\n");
fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n\r\n");
fputs($fp, "$request\r\n");
fputs($fp, "\r\n");

// Print the response
fpassthru($fp);

// Close the connection
fclose($fp);
JW

Jul 17 '05 #3
Janwillem Borleffs wrote:
With long requests it's almost always better to use the POST method
instead of GET.


Be also aware that '&' and '=' are reserved characters in request strings
and are used as parameter and parameter/value separators respectively.

When you send:

$url = 'http://test.com/Test.dll?API=test&XML='.
'&lt;FromLastName&gt;FromLast&lt;/FromLastName&gt;'.

you should urlencode the ampersands in the value of the XML parameter. See
the example I posted before.
JW

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Shaoyong Wang | last post: by
4 posts views Thread by Robert Schott | last post: by
3 posts views Thread by Ming | last post: by
10 posts views Thread by Grocery Clerk | last post: by
10 posts views Thread by Longfellow | last post: by
6 posts views Thread by rfhurley | last post: by
10 posts views Thread by Julia | last post: by
25 posts views Thread by subramanian100in | last post: by
20 posts views Thread by cscorley | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.