Actually the code:
$data = '{"params": ["testing_true", "bb4238e7-8f6d-4b2e-9ea4-43791bfb72df"], "jsonrpc": "2.0", "method": "gate.check", "id": 27034}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "tls://site.com");
curl_setopt($ch, CURLOPT_PORT, 4928);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data)
));
$output = curl_exec($ch);
var_dump(curl_error($ch));
var_dump(curl_errno($ch));
echo($output) . PHP_EOL;
curl_close($ch);
With this treatment I get
Protocol tls not supported or disabled in libcurl
Here is an example of recourse to TLS, as it is to make friends with cURL? How to make TLS connection from PHP in web server, and safely
You want HTTPS:// which is the name for the protocol that is HTTP over TLS.
So, "https://example.com" etc.
Related
I had working code that used my VPN (NordVPN) credentials through their SOCKS5 protocol.
Recently, they have dropped support for SOCKS5 so I have to use their other protocols, however I am unable to get any to work.
All of their available protocols can be seen here
https://nordvpn.com/servers/tools/
- IKEv2/IPSec
- OpenVPN
- Wireguard
- HTTP Proxy (SSL)
Here is my code, attempting to use their "HTTP Proxy (SSL)" protocol
$cookie_file = tempnam("/tmp", "CURLCOOKIE");;
$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120); // in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($ch, CURLOPT_PROXYPORT, "443");
curl_setopt($ch, CURLOPT_PROXY, "au643.nordvpn.com");
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyUser . ":" . $proxyPass);
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_URL, $Url);
$result = curl_exec($ch);
curl_close($ch);
The error I get is
curl_exec(): supplied resource is not a valid cURL handle resource in ...
I don't really care what protocol it is, just need it to work.
Thanks.
After facing the same issue, I have worked out a solution
$PROXY_HOST = "xxx.xxxxxx.com";
$PROXY_PORT = "89";
$PROXY_USER = "yourproxyusername";
$PROXY_PASS = "yourproxypassword";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_PROXY_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "$PROXY_USER:$PROXY_PASS");
curl_setopt($ch, CURLOPT_PROXY, "https://$PROXY_HOST:$PROXY_PORT");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response= curl_exec($ch);
$error = curl_error($ch);
echo $error;
echo $response;
curl_close($ch);
One thing to note is that for NordVPN you have to use the port 89 for HTTP Proxy (SSL) and the username and password is not your account username and password, but your proxy specific credentials that you can find on your account page.
Also dont quote me on this, but I think you need to use PHP 7.3+ for this to work.
we can use it with protonvpn or vpnbook ?
I am running the below Curl request and it's working.
curl -v --cert /path/to/certs/myCert.crt --key /path/to/key/myKey.key --cacert /path/to/chainedcerts/intermediary.pem https://mysite:30009/
Converting it to php as below and it's failing with error 77 with no narration. I am thinking probably file permissions could be the issue. I am using nginx and the 3 certs are owned by nginx user. If there is any other way I can view the error description as I can see the other errors
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "xmlRequest=" . $xml);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Expect:','Content-Type: text/xml']);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSLCERT, "/path/to/certs/myCert.crt");
curl_setopt($ch, CURLOPT_SSLKEY, "/path/to/key/myKey.key");
curl_setopt($ch, CURLOPT_CAINFO, "/path/to/chainedcerts/intermediary.pem ");
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$data = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
Log::error($httpcode .' : '. curl_errno($ch) .' : '. curl_error($ch));
curl_close($ch);
I am unable to connect with the Curl URL using PHP.
Below is my code, that I am trying to execute.
$url="http://b2b-dev.cenveo.com:6700/dmz/EZComm?fromTp=DiscountLabelsCustomer&toTp=DiscountLabels&operationID=DiscountLabels/1.0/PurchaseOrderRequest";
$xml_content = '<?xml version="1.0" encoding="utf-8"?><Order xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.discountlabels.com http://www.discountlabels.com/DLI_INTGR.xsd" SubmittedDate="2017-12-06 02:52:43" xmlns="http://www.discountlabels.com"><Customer><Name>Cmagnets</Name><PSCustID>987654</PSCustID></Customer><BlindDropshipAddress AddressID=""><Name></Name><Attention></Attention><PostalAddress><Address1></Address1><Address2></Address2><City></City><State></State><PostalCode></PostalCode><Country></Country></PostalAddress><Email></Email><Telephone><PhoneNumber></PhoneNumber></Telephone>
<Fax></Fax><URL></URL></BlindDropshipAddress><Item ItemNumber="1"><Product><CustomDescription>Test product.</CustomDescription>
<ProductCode>1 x 4</ProductCode><Type>Labels</Type><SubType>Standard</SubType><Shape>Rectangle</Shape><ShapeType></ShapeType>
<ProductClass>L</ProductClass><Width>1.0</Width><Height>4.0</Height><Diameter>0.0000</Diameter></Product><Quantity>1000</Quantity><Ink>Black</Ink><Artwork><ArtPath></ArtPath><UserFilename></UserFilename></Artwork><PONumber>PO12345</PONumber>
<FirstLineOfCopy>Test Copy</FirstLineOfCopy><Shipping><Quantity>1000</Quantity><ShipMethod>Fedex</ShipMethod><ShipToAddress AddressID=""><Name>Name</Name><Attention>Sally Sunshine</Attention><PostalAddress><Address1>901 Some Street</Address1>
<Address2>Suite ABC</Address2><City>New Orleans</City><State>LA</State><PostalCode>39532</PostalCode><Country>US</Country></PostalAddress><Email>sally.sunshine#somecompany.com</Email><Telephone><PhoneNumber>5419876543</PhoneNumber><Extension /></Telephone><Fax><PhoneNumber></PhoneNumber><Extension /></Fax><URL></URL></ShipToAddress><Dropship>false</Dropship>
</Shipping><Stock><StockType></StockType><StockSubType></StockSubType><StockColor></StockColor><TintColor></TintColor>
<InsideWindow>false</InsideWindow></Stock><ConsecutiveDigit><BeginDigit></BeginDigit><EndDigit></EndDigit><DigitType></DigitType><SequenceType></SequenceType></ConsecutiveDigit><ItemSpecs><Attribute>Bleed</Attribute><Value>True</Value>
</ItemSpecs><CustPONumber></CustPONumber><Comments>Item Comments</Comments></Item></Order>';
$ch = curl_init();
url_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_ENCODING, 'identity');
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,array("Content-Type: application/xml", "Accept: application/xml"));
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10); //times out after 4s
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_content); // add POST fields
curl_setopt($ch, CURLOPT_POST, 1);
$output = curl_exec($ch);
print_r($output);
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
}
After Executing the above code I am getting the below Error message.
Error: Failed to connect to b2b-dev.cenveo.com port 6700: Connection refused.
Thanks in advance
Either you're missing some headers, or you have to whitelist your server's ip address with cenveo. There is no error related to curl, just the opposite server denying your connection.
I am trying to get an Access Token on The Taboola Backstage API according to this documentation.
Backstage API - Authentication and General API Usage.pdf
My Sample Code looks like this:
$ckfile = tempnam ("/tmp", "CURLCOOKIE");
$post = array(
"client_id" => "secret"
, "client_secret" => "secret"
, "grant_type" => "client_credentials"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile );
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile );
curl_setopt($ch, CURLOPT_COOKIESESSION, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_USERAGENT, "App Client" );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60 );
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded'
));
curl_setopt($ch, CURLOPT_URL,"https://backstage.taboola.com/backstage/oauth/token/");
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_AUTOREFERER, 0);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
$result=curl_exec ($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($result, 0, $header_size);
$body = substr($result, $header_size);
var_dump($header,$body);
If I run the code I get the error message. Could not verify the provided CSRF token because your session was not found. What iam missing, i send it with POST to the right endpoint. Have someone please a tip for me?
It looks like their documentation may be slightly off. I was able to get a proper API response by posting to /backstage/oauth/token (no trailing /). With the trailing slash it tries to pass you through to a different non-API URL.
Also, it's necessary to pass the POST array through http_build_query() so that cURL doesn't do a multipart form post from the supplied array. Since it's an API, there's no need to do anything with cookies. I removed a few other unnecessary options as well.
Here is some code to get you started that worked for me:
$post = array(
"client_id" => "secret",
"client_secret" => "secret",
"grant_type" => "client_credentials",
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIESESSION, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_USERAGENT, "App Client" );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60 );
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded',
'Accept: application/json',
));
curl_setopt($ch, CURLOPT_URL,"https://backstage.taboola.com/backstage/oauth/token");
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_AUTOREFERER, 0);
$result=curl_exec ($ch);
$info = curl_getinfo($ch);
$response = json_decode($result, true);
if ($info['http_code'] == 200) {
// okay
$access_token = $response['access_token'];
var_dump($response);
} else {
// error
echo $response['error'] . ': ' . $response['error_description'];
}
I am using curl library to get the XML but getting error of connection with host. Following is my code, I have just removed the credentials.
$url="https://interface.callport.net:8080/P-RVWR-drcm01-cti/call/2142100570";
$curl_post_data = array(
"query_type" => 'caller_info',
"dnis" => '8883874944',
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, base64_encode('webapi#fastfix:color43t'));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curl_post_data);
$result = curl_exec($ch);
if(curl_errno($ch))
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
echo $result;
}
curl_close($ch);
It's SSL so this usually fixes the problem. cURL does not verify the certificate then.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
[edit] I solved the problems. First the SSL as described above, then I removed the base64 encoding of the username and password, changed so the data is sent by GET instead of POST and lastly fixed the headers.
$url="https://interface.callport.net:8080/P-RVWR-drcm01-cti/call/2142100570?query_type=caller_info&dnis=8883874944";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'webapi#fastfix:color43t');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);