[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

curl with https example

Posted on 2010-03-23
11
Medium Priority
?
1,297 Views
Last Modified: 2012-05-09
good example code in c linux using libcurl with https, curl over https
0
Comment
Question by:tittu
11 Comments
 
LVL 41

Expert Comment

by:noci
ID: 28424868
I have no code myself.. but have you looked at the source of the commandline tool of curl.

All things you need from the commandline are translated to libcurl commands.
The following options are relevant to ssl:
--engine, --egd-file, --cert, --cert-type, --cacert, --capath, --insecure, --key, --key-type, --random-file, -1, -2, -3
0
 

Author Comment

by:tittu
ID: 28429334
please provide any example code using https and curl
0
 
LVL 41

Expert Comment

by:noci
ID: 28436493
Here is the source:

http://curl.haxx.se/download/curl-7.20.0.tar.gz

Look at the curl commandline tool for the handling of the above items.

At least --cacert / --capath is needed for verifying the remote server.
--cert / --key might be needed if you need to authenticate

The others depend on specific use -2 = ssl2, -3 = ssl3, -1 = tls
if you use special ssl hanling (engines) you need to select one... etc.
But the use of that SHOULD be documented with assignment you have.
0
Evaluating UTMs? Here's what you need to know!

Evaluating a UTM appliance and vendor can prove to be an overwhelming exercise.  How can you make sure that you're getting the security that your organization needs without breaking the bank? Check out our UTM Buyer's Guide for more information on what you should be looking for!

 
LVL 41

Expert Comment

by:HonorGod
ID: 28443326
http://curl.haxx.se/docs/httpscripting.html

See sections
11. HTTPS
11.1 Certificates

Does this help?
0
 

Author Comment

by:tittu
ID: 30100890
I am asking curl api to send/get https request and the api usage example , not the curl source code
0
 
LVL 41

Expert Comment

by:noci
ID: 30137081
The curl source code DOES use the api. The commandline tool is a very thin layer where a commandline option
like --capath is just calling everything that is needed to specify a CAPATH to the curl layer.
So if you actually care to check the curl commandline source, lookup where --capath is handled you know what to do.
You can prototype on a command line the exact options you need and spell those out.

(And the curl code is quite good accessible, I did the initial port of it to OpenVMS some years ago.)
0
 

Expert Comment

by:mlecce
ID: 30137710
I think this is what you would want (it is in C++).
#include <stdio.h>
#include <curl/curl.h>
 
int main(void)
{
  CURL *curl;
  CURLcode res;
 
  curl = curl_easy_init();

  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "https://www.experts-exchange.com/");
 
    res = curl_easy_perform(curl);
 
    /* always cleanup */ 
    curl_easy_cleanup(curl);
  }

  return 0;
}

Open in new window

0
 
LVL 41

Expert Comment

by:noci
ID: 30142422
Yes and some options for setting up certificate checking. like specifying the CA_PATH etc.
and you example is still C.
0
 

Author Comment

by:tittu
ID: 31921300
C/C++ no problem how to setup curl with certificate .pem file
0
 
LVL 41

Accepted Solution

by:
noci earned 1500 total points
ID: 32067906
http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#SSL

is a good starting point:
CURLOPT_CAPATH  (to verify remote)
CURLOPT_SSL_VERIFYPEER (if you want to verify)

CURLOPT_CERT & CURLOPT_SSLKEY etc. are used to specify an authentication cert.

0
 

Author Closing Comment

by:tittu
ID: 32695632
working
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have written articles previously comparing SARDU and YUMI.  I also included a couple of lines about Easy2boot (easy2boot.com).  I have now been using, and enjoying easy2boot as my sole multiboot utility for some years and realize that it deserves …
Often times it's very very easy to extend a volume on a Linux instance in AWS, but impossible to shrink it. I wanted to contribute to the experts-exchange community a way of providing a procedure that works on an AWS instance. It can also be used on…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question