简体   繁体   中英

Curl API and command line options to Authenticate with user name & password enabled https url

I am trying to authenticate against a HTTPS URL with "user name and password" using C-based curl API's and curl command line arguments in linux ( Fedora 14 curl 7.30.0 (i686-pc-linux-gnu) libcurl/7.30.0 OpenSSL/1.0.0 zlib/1.2.5 ) 在此处输入图片说明 ) platform.

When I use the URL in the Mozilla web browser it prompts for the username, password once - after I press "OK" I am able to get the content. But if I press the cancel button, "Login Cancelled by User" is shown. The error (screenshot) is attached.

How to authenticate and avoid "Login cancelled by user" exception using curl API's and command line arguments?

Below are the options I have tried, but still the error remains the same - "Login cancelled by user"

Command Line:

curl -k --user "xxxxx:xxxxx" "https://fsgpos.opensoft.co.bw/ipa/statement/get/LN001234"

Curl API:

curl_easy_setopt(curl, CURLOPT_USERNAME,"xxxxxxxx");

curl_easy_setopt(curl, CURLOPT_PASSWORD,"xxxxxxxx");

How to handle this exception with valid curl options and API arguments?

curl -X POST http://<auth url> --user "<username>:<password>" -c ~/cookies
  • -c(可选)将登录信息存储在cookie中

Are you providing client cert, client key and root cert

curl_easy_setopt(pcurlHandle, CURLOPT_SSLCERT, clientcertfile);

curl_easy_setopt(pcurlHandle, CURLOPT_SSLKEY, clientkeyfile);

curl_easy_setopt(pcurlHandle, CURLOPT_CAINFO, rootcertfile);

Your code would be helpful to debug.

Use UserAgent string with your curl. This is the only thing you are missing compare to the browser.

    -A "Mozilla 6.0"

Also, add the -v parameter also, and show us the debug message of curl.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM