I am trying to add information into the rest web service at a particular port number: 8999. On localhost, it is working fine but on the live server, it gives the following error:
cURL Error (28): connect() timed out!
Here is the code
$ch = curl_init('http://int.otono-me.com:8999/api/customers/new');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_PORT, 8999);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"X-Auth-Token: " . $_SESSION["Token"]
));
$result = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
if($curl_errno > 0) {
echo "cURL Error ($curl_errno): $curl_error\n";
} else {
echo "Successful\n";
}
curl_close($ch);
echo $result;
Any suggestion on what needs to be done?
Either you have a proxy on the live system,
or a firewall in between.
Ask your local sysop for changes regarding firewall.
You are also missing a ':
$ch = curl_init('http://int.otono-me.com:8999/api/customers/new');
// -------^
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://int.otono-me.com:8999/api/customers/new");
also your link is not answering
Don't implement your PORT in your URL. Send separatelly URL and PORT:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://int.otono-me.com/api/customers/new");
curl_setopt($ch, CURLOPT_PORT, 8999);
Related
In a certain API script, I want to run an AJAX file from within a PHP file, to post the vars to the AJAX file. I'd prefer not having to include the AJAX file for a nicer solution, since it's made to receive post vars. When I run the cURL locally using XAMPP I get the following error:
Curl error: Could not resolve host: C
Is semicolon an invalid char for cURL? How can I run cURL locally, pointing towards a file on the same server?
$isLocal = (!empty($_SERVER['HTTP_HOST']) && strpos($_SERVER['HTTP_HOST'], 'localhost') !== false);
if ($isLocal) {
$documentRootWildcard = 'C:/_foretag/TourTask/Internet/Hemsidor/example.com';
} else {
$documentRootWildcard = '/home/user5/_domains/example.com';
}
$curlUrl = $documentRootWildcard . '/ajax/bookings/save.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $curlUrl);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, 'ea5e7f894cde433a987d9b9979dfed5f:7ff527e78ace4e9291ee6f7a7d52141e');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/json')
);
$curlResponse = curl_exec($ch);
if ($curlResponse === false) {
echo 'Curl error: ' . curl_error($ch);
} else { //Successfully sent
}
curl_close($ch);
How can I solve this? Or is there a better solution? Thank you!
I followed the instructions in the official vsphere site to get info from the server and from the answer of another user here .
From what I have understood, firstly I have to get the session id (cis id), but I got "null" as a result.
I tried multiple codes but the result is the same:
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$headers = array(
'Content-Type: application/json',
'Accept: application/json',
'vmware-use-header-authn: test'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, "https://vcsa/rest/com/vmware/cis/session");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, 'administrator#vs.dom:userpassword');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
$out = json_decode(curl_exec($ch));
// var_dump($out);
if ($out === false) {
echo 'Curl Error: ' . curl_error($ch);
exit;
}
$sid = $out;
dd($out);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("vmware-api-session-id:$sid"));
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, "https://vcsa/rest/vcenter/vm");
$output = curl_exec($ch);
$vms = json_decode($output);
var_dump($vms);
curl_close($ch);
The result is null.
this is a script word 100% using PHP
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, "https://{ip}/rest/com/vmware/cis/session");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, 'username' . ":" . 'password');
$out = json_decode(curl_exec($ch));
// var_dump($out);
if ($out === false) {
echo 'Curl Error: ' . curl_error($ch);
exit;
}
$sid = $out->value;
curl_setopt($ch, CURLOPT_HTTPHEADER, array("vmware-api-session-id:$sid"));
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, "https://{ip}/rest/vcenter/vm");
$output = curl_exec($ch);
$vms = json_decode($output);
var_dump($vms);
curl_close($ch);
?>
when you debug your code, the $out variable return null?
If yes, can you check if your curl returns 56 - OpenSSL SSL_read: Success error in $out = json_decode(curl_exec($ch));?
This error occoured with my code, and I see wich cURL in 7.67 version cause this trouble.
My solution was to downgrade cURL version to 7.65.
It works for me!
I had the same problem, and eventually understood that it is caused by this header:
curl_setopt($ch, CURLOPT_POST, true);
And replacing it with this one solves the issue:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
I try to connect to socks5 proxy using libcurl, however I receive the answer SOCKS: authentication failed. I also tried to connect to the proxy server through a Powershell script with cURL – it works, so the proxy server is available and my login and password are correct. I tried a lot of solutions... But connection via PHP-script still does not work.
PHP version – 5.4, cURL version – 7.19. What can I do?
[UPDATE] Here is my current code. I want to send message with my Telegram bot :)
$proxy = '<hostname>:<port>';
$proxy_auth = '<username>:<password>';
$url = 'https://api.telegram.org/bot<botID>/sendMessage?'.'chat_id='.$chat_id.'&parse_mode='.$parse_mode.'&text='.'test';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_auth);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, true);
$curl_scraped_page = curl_exec($ch);
$error = curl_error($ch);
echo $error;
echo $curl_scraped_page;
curl_close($ch);
Here is the complete answer for anyone else having the same issue.
//Curl setup
$url = "https://google.com";
$proxy = "10.23.2.2:8080";
$password = "username:secret_passowrd";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_HEADER, true);
//proxy's address
curl_setopt($ch, CURLOPT_PROXY, $proxy);
//proxy's password
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $password);
//in order to follow redirects.
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//in order to use the result of the query
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//run query
$curl_scraped_page = curl_exec($ch);
$error = curl_error($ch);
echo $error;
echo $curl_scraped_page;
curl_close($ch);
Hope that helps.
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.
When i am making a payment in paypal, its throws "SSL connect error (35)", even i have a enabled TLS. And also i have tested with "https://tlstest.paypal.com", is also return same error.
Following sample i used to test TLS.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://tlstest.paypal.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSLVERSION, 6); // CURL_SSLVERSION_TLSv1_2
curl_setopt($ch, CURLOPT_CAINFO, 'cacert.pem');
$result = curl_exec($ch);
echo 'result = '.$result.'<br>';
echo 'errno = '.curl_errno($ch).'<br>';
echo 'error = '.curl_error($ch).'<br>';
curl_close($ch);
Thanks in advance