Thank you all for your help, I have it working, along with an extra line after header it also need Host for authentication and Content-Length for the message to be properly parsed.
"POST /emp/ HTTP/1.1\r\nHost: 192.168.16.10\r\nAuthorization: Basic YWRtaW46cGFzcw==\r\nContent-Type: application/json\r\nContent-Length: 1471\r\n\r\n%s\r\n" -----Original Message----- From: curl-library [mailto:curl-library-boun...@cool.haxx.se] On Behalf Of Daniel F via curl-library Sent: Tuesday, July 20, 2021 3:22 AM To: libcurl development <curl-library@cool.haxx.se> Cc: dan...@poradnik-webmastera.com Subject: Re: How to authenticate when using “CURLOPT_CONNECT_ONLY” so I can use non-blocking curl_easy_send() and curl_easy_recv() You must add extra empty line after headers, to tell server where they end and content starts. So you should send this: "POST /emp/ HTTP/1.1\r\nAuthorization: Basic YWRtaW46cGFzcw==\r\nContent-Type: application/json\r\n\r\n%s" Daniel W dniu 2021-07-19 19:24, Venkat Maddisetti via curl-library napisał(a): > Before coming here I realized curl_easy_setopt has no effect setting > username and password so I tried to send it as part of post message > using curl_easy_send() as below but I am not receiving any response > back from server making me believe authentication did not go properly > and wondering what is the correct way of doing it. > > "POST /emp/ HTTP/1.1\r\nAuthorization: Basic > YWRtaW46cGFzcw==\r\nContent-Type: application/json\r\n%s" > > send:POST /emp HTTP/1.1 > > Authorization: Basic YWRtaW46cGFzcw== > > Content-Type: application/json > > { > > Json: data > > } > > FROM: curl-library [mailto:curl-library-boun...@cool.haxx.se] ON > BEHALF OF Zakrzewski, Jakub via curl-library > SENT: Monday, July 19, 2021 2:38 AM > TO: libcurl development <curl-library@cool.haxx.se> > CC: Zakrzewski, Jakub <jakub.zakrzew...@scheer-group.com> > SUBJECT: Re: How to authenticate when using “CURLOPT_CONNECT_ONLY” > so I can use non-blocking curl_easy_send() and curl_easy_recv() > > You have literally told curl to connect and do nothing else. BasicAuth > is a part of HTTP protocol and done via HTTP headers which will not be > send with CURLOPT_CONNECT_ONLY. If you want to continue using > CURLOPT_CONNECT_ONLY, you'll have to do the HTTP part yourself. > > ------------------------- > > FROM: curl-library <curl-library-boun...@cool.haxx.se> on behalf of > Venkat Maddisetti via curl-library <curl-library@cool.haxx.se> > SENT: 19 July 2021 05:38 > TO: curl-library@cool.haxx.se <curl-library@cool.haxx.se> > CC: Venkat Maddisetti <vmaddise...@sharedspectrum.com> > SUBJECT: How to authenticate when using “CURLOPT_CONNECT_ONLY” so I > can use non-blocking curl_easy_send() and curl_easy_recv() > > Hello there!, I am using libcurl to interface with over the shelf http > server box and having issue with authentication while using > “CURLOPT_CONNECT_ONLY” option to be able to use curl_easy_send() and > curl_easy_recv(), so my question is: > > HOW TO (BASIC) AUTHENTICATE WHEN USING “CURLOPT_CONNECT_ONLY” SO I CAN > USE NON-BLOCKING CURL_EASY_SEND() AND CURL_EASY_RECV() ? > > To give some background, I am able to authenticate and able to work > with the box with the blocked call ( without CURLOPT_CONNECT_ONLY > option) with no control over the curl connection. The problem is, > since the response from the box is a stream of data there is no way > for me to stop the stream and send an another request. So from the > documentation I figured out “CURLOPT_CONNECT_ONLY” is the way to go, > and using the socket handle I can manage the communication to the box > but after adding “CURLOPT_CONNECT_ONLY” option, I am not receiving the > data stream as expected, I guess my request went through as there are > no errors thrown, but looking closely I did not see authentication > happening – I assume that is the problem, I am not doing anything > fancy here just basic authentication only. Searched the web but could > not get an answer and I am stuck. What am I missing here, does this > option go in tandem with some other option I could not figure out or > is there a different approach to authenticate while using this option. > > Below is the verbose logs I captured with and without the option and > very much appreciate your help. > > WITH CURLOPT_CONNECT_ONLY OPTION: > > Curl Version is libcurl/7.73.0 > > HTTPS query = http://192.168.16.10/emp/ [1] > > curl_test_main ... > > send:POST / HTTP/1.1 > > Content-Type: application/json > > { > > Json: data > > } > > * STATE: INIT => CONNECT handle 0x1cba3bb3c20; line 1796 (connection > #-5000) > > * Added connection 0. The cache now contains 1 members > > * family0 == v4, family1 == v6 > > * Trying 192.168.16.10:80... > > * STATE: CONNECT => WAITCONNECT handle 0x1cba3bb3c20; line 1857 > (connection #0) > > * Connected to 192.168.16.10 (192.168.16.10) port 80 (#0) > > * STATE: WAITCONNECT => SENDPROTOCONNECT handle 0x1cba3bb3c20; line > 1990 (connection #0) > > * Marked for [keep alive]: HTTP default > > * STATE: SENDPROTOCONNECT => DO handle 0x1cba3bb3c20; line 2011 > (connection #0) > > * STATE: DO => DONE handle 0x1cba3bb3c20; line 2042 (connection #0) > > * multi_done > > * Connection #0 to host 192.168.16.10 left intact > > * Expire cleared (transfer 0x1cba3bb3c20) > > curl_easy_perform > > Sending request. > > Sent 235 bytes. > > Reading response. > > Transfer rate: 0 KB/sec (0 bytes in 0 seconds) > > WITHOUT CURLOPT_CONNECT_ONLY OPTION: > > Curl Version is libcurl/7.73.0 > > HTTPS query = http://192.168.16.10/emp/ [1] > > curl_test_main ... > > curl_easy_perform ... > > * STATE: INIT => CONNECT handle 0x209e919b2a0; line 1796 (connection > #-5000) > > * Added connection 0. The cache now contains 1 members > > * family0 == v4, family1 == v6 > > * Trying 192.168.16.10:80... > > * STATE: CONNECT => WAITCONNECT handle 0x209e919b2a0; line 1857 > (connection #0) > > * Connected to 192.168.16.10 (192.168.16.10) port 80 (#0) > > * STATE: WAITCONNECT => SENDPROTOCONNECT handle 0x209e919b2a0; line > 1990 (connection #0) > > * Marked for [keep alive]: HTTP default > > * STATE: SENDPROTOCONNECT => DO handle 0x209e919b2a0; line 2011 > (connection #0) > > * Server auth using Basic with user 'admin' > >> POST /emp/ HTTP/1.1 > > Host: 192.168.16.10 > > Authorization: Basic YWRtaW46cGFzcw== > > Accept: */* > > Content-Type: application/json > > Content-Length: 1471 > > * upload completely sent off: 1471 out of 1471 bytes > > * STATE: DO => DO_DONE handle 0x209e919b2a0; line 2082 (connection #0) > > > * STATE: DO_DONE => PERFORM handle 0x209e919b2a0; line 2203 > (connection #0) > > * Mark bundle as not supporting multiuse > > * HTTP 1.1 or later with persistent connection > > < HTTP/1.1 200 OK > > < Server: nginx/1.6.2 > > < Date: Fri, 16 Jul 2021 17:29:28 GMT > > < Content-Type: text/event-stream > > < Transfer-Encoding: chunked > > < Connection: keep-alive > > < X-CRFS-MissionProcessor-Software-Version: 1.5.1.19 > > < X-CRFS-MissionProcessor-Protocol-Version: 0.10 > > < Access-Control-Allow-Origin: * > > < Cache-Control: private, max-age=0 > > < X-Content-Type-Options: nosniff > > < X-XSS-Protection: 1; mode=block > > < > > Thanks for help in advance!! > > > > Links: > ------ > [1] http://192.168.16.10/emp/ > ------------------------------------------------------------------- > Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library > Etiquette: https://curl.se/mail/etiquette.html ------------------------------------------------------------------- Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library Etiquette: https://curl.se/mail/etiquette.html ------------------------------------------------------------------- Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library Etiquette: https://curl.se/mail/etiquette.html