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/
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/
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!!

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html

Reply via email to