Sorry for any confusion, as I mentioned originally, http post works for me as laid out in the example and authentication is not a problem there. Since the response is a stream of data and curl_easy_perform() never returns and the thread is blocked. So I tried using CURLOPT_CONNECT_ONLY where I have a non-blocking send/recv and figured out sending CURLOPT_USERPWD or CURLOPT_USERNAME & CURLOPT_PASSWORD along with CURLOPT_CONNECT_ONLY goes unused as it was not complaining even when I send wrong username/password. Then I tried sending authentication and content-type as part of the http post header along with data using curl_easy_send() but still I guess it is not able to authenticate (as it does not complain about wrong password used) and I do not have response or any errors reported back.
Here is the string I am sending with curl_easy_send(), "POST /emp/ HTTP/1.1\r\nAuthorization: Basic YWRtaW46cGFzcw==\r\nContent-Type: application/json\r\n%s" In reference with string used in sendrecv.c example: const char *request = "GET / HTTP/1.0\r\nHost: example.com\r\n\r\n"; the difference is: GET vs POST and Authentication & Content-Type in my header, which I hope I am doing it right but highly doubtful and need some guidance. -----Original Message----- From: Daniel Stenberg [mailto:dan...@haxx.se] Sent: Monday, July 19, 2021 5:26 PM To: Venkat Maddisetti via curl-library <curl-library@cool.haxx.se> Cc: Venkat Maddisetti <vmaddise...@sharedspectrum.com> Subject: RE: How to authenticate when using “CURLOPT_CONNECT_ONLY” so I can use non-blocking curl_easy_send() and curl_easy_recv() On Mon, 19 Jul 2021, Venkat Maddisetti via curl-library wrote: > Before coming here I realized curl_easy_setopt has no effect setting > username and password CURLOPT_USERPWD, CURLOPT_USERNAME and CURLOPT_PASSWORD included ? > "POST /emp/ HTTP/1.1 If you want HTTP, then using CONNECT_ONLY + send/recv is *extremely* rarely the right answer. You seem to want a plain POST with Basic auth and libcurl does that pretty well and simply with the regular easy API. First, get the http-post.c example Then set CURLOPT_USERNAME and CURLOPT_PASSWORD Then set the right Content-type and make sure the right request body is sent. Doesn't that cover it? -- / daniel.haxx.se | Commercial curl support up to 24x7 is available! | Private help, bug fixes, support, ports, new features | https://www.wolfssl.com/contact/ ------------------------------------------------------------------- Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library Etiquette: https://curl.se/mail/etiquette.html