Viewed   79 times

I am having problem with PHP curl request with basic authorization.

Here is the command line curl:

curl -H "Accept: application/product+xml" "https://{id}:{api_key}"

I have tried by setting curl header in following ways but it's not working

Authorization: Basic id:api_key
Authorization: Basic {id}:{api_key}

I get the response "authentication parameter in the request are missing or invalid" but I have used proper id and api_key which is working in command line curl (I tested)

Please help me.



Try the following code :


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result=curl_exec ($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);   //get status code
curl_close ($ch);
Thursday, August 18, 2022

cURL is not able to verify the authenticity of the certificate being used, because the certificate for the signing authority cannot be found in the local database.

This might be symptomatic of a self signed certificate being used.

What you should do is add the certificate for the signing authority to /etc/ssl/certs/ca-certificates.crt.

What you can do is use curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);, which will disable the check that is failing.

You really should use the first option.

Wednesday, August 31, 2022

Ok so finally found a solution. It helps to read documentations on the classes you use and different systems used. In my case i was trying to integrate my app with microsoft dynamics 365 ax, so i had to read up on that too.

I read a lot of documents some were related to different dynamics service but this one helped most

And since the soap service needed Authorization Header, because they were using Windows authentication, we needed to get the token from oAuth link.$tenantDomainName/oauth2/token

PS: the oauth2 link i knew about it from github PHPConsoleApplication

I used PHP CURL to get my authorization Token and then created a client using PHP's SoapClient Class.

Make sure you add the authorization token in the header like so:

$arrayOpt = array(    
'stream_context'  => stream_context_create(
                            array('http' =>'Authorization: Bearer tokenString')

$client = new SoapClient($wsdl, $arrayOpt);

$response = $client->serviceMethod($parameters);


And you will get the values of the method.

Friday, December 9, 2022

Use strftime instead of date:

setlocale( LC_TIME, "fr_FR" );
$formated_date_new = strftime( "%d %b %Y", strtotime( $this_date ) );

strftime refernce:

Monday, December 26, 2022

Using jq for this, as Charles Duffy's answer suggests, is a very good idea. However, if you can't or do not want to install jq here is what you can do with plain POSIX shell.

set -e

current_ip="$(curl --silent --show-error --fail"
echo "IP: $current_ip"

# Update A record
curl -X PUT "" 
    -H "X-Auth-Email: EMAILHERE" 
    -H "X-Auth-Key: AUTHKEYHERE" 
    -H "Content-Type: application/json" 
    --data @- <<END;
    "id": "ZONEIDHERE",
    "type": "A",
    "name": "",
    "content": "$current_ip",
    "zone_name": ""
Friday, November 18, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :