Connecting Tech Pros Worldwide Help | Site Map

fopen question.

theouimets@hotmail.com
Guest
 
Posts: n/a
#1: Jul 17 '05
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);
?>

steve
Guest
 
Posts: n/a
#2: Jul 17 '05

re: fopen question.


"theouimets" wrote:[color=blue]
> 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[/color]
and[color=blue]
> some XML. It seems to get to a certain point and then produce an[/color]
error[color=blue]
> with no details and just cuts it off.
>
> snip...
> ?>[/color]

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
Janwillem Borleffs
Guest
 
Posts: n/a
#3: Jul 17 '05

re: fopen question.


theouimets@hotmail.com wrote:[color=blue]
> 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.
>[/color]

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



Janwillem Borleffs
Guest
 
Posts: n/a
#4: Jul 17 '05

re: fopen question.


Janwillem Borleffs wrote:[color=blue]
> With long requests it's almost always better to use the POST method
> instead of GET.
>[/color]

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



Closed Thread


Similar PHP bytes