Jump to content

PHP cURL: manage ports - how?


seoneo

Recommended Posts

Hi all!

There is an ASPX-page what I open in a browser and I get back an XML-code. I need to use it in PHP.

My idea was I would "iclude" it with cURL. I can use with an ordinary page like google, but it fails when I use on a special port.

How can I do it? Thanks the answers.

 

This is the code, what I use:

//http://www.domain.com:1234/path/file.aspx?p1=value

$url = "http://www.domain.com/path/file.aspx";
$port = 1234;
$postdata  = "p1=value";

$cinit = curl_init(); 

curl_setopt($cinit, CURLOPT_URL, $url); 
curl_setopt ($cibit, CURLOPT_PORT , $port); 

curl_setopt ($cinit, CURLOPT_TIMEOUT , 10);
curl_setopt($cinit, CURLOPT_RETURNTRANSFER, 1); 

curl_setopt($cinit, CURLOPT_POST, 1);
curl_setopt($cinit, CURLOPT_POSTFIELDS, $postdata);

$cexec = curl_exec($cinit); 

print_r(curl_getinfo($cinit)); 
echo "<hr>Error code:" .curl_errno($cinit); 
echo "<br>Error name:" . curl_error($cinit); 

curl_close($cinit); 
echo $cexec;

Link to comment
https://forums.phpfreaks.com/topic/203778-php-curl-manage-ports-how/
Share on other sites

Oh, thanks, I had corrected it earlier and I forgot to repair this mistake.

 

A few minutes ago, I tried to use curl in console in my computer, and it runs successfully:

curl http://www.domain.com:1234/path/file.aspx?p1=value

 

After that my idea was I should use only CURLOPT_URL (with whole path) without CURLOPT_PORT, but it didn't work.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.