PHP Curl with port number issue

Asked
Active3 hr before
Viewed126 times

7 Answers

90%

and try this curl_setopt($ch, CURLOPT_PORT, 8088);,I am unable to make a php curl request with port number , without port number i am getting response properly.,Try to set the port like this:, i tried with curl_setopt($ch, CURLOPT_PORT, 8088); also but same result. I have also tried by removing curl_setopt($ch, CURLOPT_PORT, 8088); – druveen Aug 25 '11 at 10:55

Try to set the port like this:

curl_setopt($ch, CURLOPT_PORT, $_SERVER['SERVER_PORT']);

or:

curl_setopt($ch, CURLOPT_PORT, 8088);
load more v
88%

The callback is only called when the CURLOPT_NOPROGRESS option is set to false. , The CURLOPT_XXX option to set. , Set the name of the network interface that the DNS resolver should bind to. This must be an interface name (not an address). , The default protocol to use if the URL is missing a scheme name.

load more v
72%

Just a note, I've had this issue before because the web host I was using was blocking outbound ports aside from the standard 80 and 443 (HTTPS). So you might want to ask them or do general tests. In fact, some hosts often even block outbound on port 80 for security.,Once you've established you can connect, then you can go about the horrible business of using PHP Curl. There are wrappers, but they're flaky that I've found. ,today I am trying to make a curl call to somesite which is listening to port 8080. However, calls like this get sent to port 80 and not 8080 instead:,Both Curl, Wget or similar can be very easily configured to use GET and POST methods. It's not advisible, but for more than one complicated operation using Curl I've simply given up trying to configure PHP's library correctly and simply dropped to the command line.

today I am trying to make a curl call to somesite which is listening to port 8080. However, calls like this get sent to port 80 and not 8080 instead:

$ch = curl_init();
curl_setopt($ch, CURLOPT_PORT, 8080);
curl_setopt($ch, CURLOPT_URL, 'http://somesite.tld:8080');
curl_setopt($ch, CURLOPT_POST, count($data));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$target_response = curl_exec($ch);
curl_close($ch);
load more v
65%

curl_setopt($ch, CURLOPT_PORT, 11740);,Bear in mind, you may face problems with SELinux: ,Unable to make php curl request with port number ,Since you're using PHP, you will probably need to use the CURLOPT_PORT option, like so:

Yes, it's possible, the syntax is curl [protocol://]<host>[:port], for example:

curl example.com: 1234
load more v
75%

Is that online server a unix variant? You can ping from that online server to DHIS2 server ?,Additionally you can configure nginx to avoid the using port explicitily,This is exactly the result that I want for the URL with numbers and a port.,You can also try telnet 12.113.12.186 8083 from online server to see port 8083 is reachable.

I have the following code in PHP and whenever I run it from my cpanel server, the result is always false. Could it be as a result of security or something else? Do not mind the URL and credentials, those are wrong I just wanted to demonstrate my problem.

		< ? php
		header("access-control-allow-origin: *");
		$username = 'admin';
		$password = 'Pass*#21_!';

		$url = 'http://12.113.12.186:8083/api/dataValueSets.json?dataSet=%&period=%&orgUnit=%';

		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
		curl_setopt($ch, CURLOPT_USERPWD, "".$username.
		   ":".$password.
		   "");
		curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

		$output = curl_exec($ch);

		curl_close($ch);

		echo $output; ?
		>
load more v
40%

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PORT, long number); ,CURLOPT_PORT - remote port number to connect to ,Used for all protocols that speak to a port number. ,This option sets number to be the remote port number to connect to, instead of the one specified in the URL or the default port for the used protocol.

CURL * curl = curl_easy_init();
if (curl) {
   curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
   curl_easy_setopt(curl, CURLOPT_PORT, 8080 L);
   ret = curl_easy_perform(curl);
   curl_easy_cleanup(curl);
}
22%

PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs , PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs ,PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs.,Check for open issues or open a new issue to start a discussion around a bug or feature.

$ composer require php - curl - class / php - curl - class
load more v

Other "undefined-undefined" queries related to "PHP Curl with port number issue"