Viewed   111 times

Im trying to convert a curl-statement with an authentication header to a php curl request. But it doesn't seem to be working, because I receive the error below with echo 'error:' . curl_error($ch);:

error:SSL certificate problem: unable to get local issuer certificate

My curl-command looks like this:

curl --user XXXX:YYYY "URL"

My php-curl looks like this:

$login = 'XXXX';
$password = 'YYYY';
$url = 'URL';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
echo curl_exec($ch);
$result = curl_exec($ch);

if ($result != false){
        echo "SUCCESS";
        echo "<br>";
        echo 'error:' . curl_error($ch);
        echo "<br>";

Does anyone sees my fault?



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

this is what you want: remove CURLOPT_POSTFIELDS altogether, and replace CURLOPT_CUSTOMREQUEST=>'PUT' with CURLOPT_UPLOAD=>1 and replace 'r' with 'rb', and use CURLOPT_INFILE (you're supposed to use INFILE instead of POSTFIELDS),

$fp = fopen($_FILES['file']['tmp_name'], "rb");

This works when I had $file = fopen($temp_name, 'r');

never use the r mode, always use the rb mode (short for "binary mode"), weird things happen if you ever use the r mode on Windows, r is short for "text mode" - if you actually want text mode, use rt (and unless you really know what you're doing, you don't want the text mode, ever, unfortunate that it's the default mode),

but the file uploaded was a weird file. (...) This is what the file looks like when the person at the other end of this API tries to open it.

well you gave CURLOPT_POSTFIELDS a resource. CURLOPT_POSTFIELDS accepts 2 kinds of arguments, #1: an array (for multipart/form-data requests), #2: a string (for when you want to specify the raw post body data), it does not accept resources.

if the php curl api was well designed, you would get an InvalidArgumentException, or a TypeError, when giving CURLOPT_POSTFIELDS a resource. but it's not well designed. instead, what happened is that curl_setopt implicitly casted your resource to a string, hence resource id #X , it's the same as doing

curl_setopt($request, CURLOPT_POSTFIELDS, (string) fopen(...));
Thursday, August 25, 2022

I get the output of the page when running


This also works for me:

$ch = curl_init('');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$out = curl_exec($ch);

echo $out;

Edit: Just tried your code posted and it works fine for me. Perhaps the string you are passing into get_web_page() is wrong?

Monday, September 12, 2022

From your commandline you are directly posting the file as binary data. So send the content like below.

curl_setopt($cURLHandler, CURLOPT_POSTFIELDS, file_get_contents("batchjob.txt"));
Monday, August 15, 2022

I would say that you should use the API that Proliphix is providing.

As you can see, they provide an example, and you've already managed to figure out how to provide the correct parameters through cURL so now you "just" need to convert this to Swift.

For this you need a HTTP networking API, you could use either the NSURLSession API provided by Apple, or perhaps Alamofire, just to mention a pair.

These API's take an URL which would be /get or /pdp in your case. Then you need to tell them wether this is a GET or a POST request. If the API needs any data (like the OID parameters in your case), you'll need to provide that as well and then you need to set up eventual headers.

Then you send your request and wait for an answer, which you then react to.

Here is an example on how to do this with NSURLSession:

if let url = NSURL(string: ""){
    let request = NSMutableURLRequest(URL: url)
    request.HTTPMethod = "POST" //Or GET if that's what you need
    request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")  //This is where you add your HTTP headers like Content-Type, Accept and so on
    let params = ["OID1.2" : "SW+Dev+114", "OID1.4" : ""] as Dictionary<String, String> //this is where you add your parameters

    let httpData = NSKeyedArchiver.archivedDataWithRootObject(params) //you need to convert you parameters to NSData or to JSON data if the service accepts this, you might want to search for a solution on how to do this...hopefully this will get you in the right direction :-)
    request.HTTPBody = httpData
    let session = NSURLSession.sharedSession()
    session.dataTaskWithRequest(request, completionHandler: { (returnData, response, error) -> Void in
        var strData = NSString(data: returnData, encoding: NSUTF8StringEncoding)
    }).resume() //Remember this one or nothing will happen :-)

Hope this gets you in the right direction. You could also do a Google search for NSURLSession or Alamofire tutorial, now that you know what to search for.

Thursday, September 1, 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 :