How do I get cURL (CLI) to close the connection made to a https server? - http

cURL doesn't seem to care about closing the connection to a server even when I include the "Connection: close" header?
It respects the header for http, but not for https, seems like?
curl -v -H "Connection: close" -o nul --http2 http://www.google.com
results in
* Closing connection 0
but curl -v -H "Connection: close" -o nul --http2 http://www.google.com
results in
* Connection #0 to host www.google.com left intact
I get that in isolation this isn't an issue, but I want to test session resumption in a custom https server, for which I need to request the url twice in succession, with the connecting being closed in between the two, which doesn't seem to happen; something along the lines of:
curl -v -k --http2 --tls-max 1.3 -o nul -H "Connection: close" <url> <url>
and in the logs of the second request, I see "Re-using existing connection! (#0) with host ", which I do not want.

Related

Telegram webhook "Connection timeout"

Our Telegram bot [TOKEN_OMITTED] never 'hooks' with our server.
This URL https://api.telegram.org/bot[TOKEN_OMITTED]/getWebhookInfo
gives this response with 'Connection timeout' error:
{"ok":true,"result":{"url":"https://[DOMAIN_OMITTED].com/PHP/telWH2.php","has_custom_certificate":true,"pending_update_count":0,"last_error_date":1624178810,**"last_error_message":"Connection
timed out"**,"max_connections":40,"ip_address":"123.456.789.000"}}
However this command (copied from https://core.telegram.org/bots/webhooks#testing-your-bot-with-updates) works pretty well (so there seems not to be such 'Connection timeout' problem):
curl --tlsv1.2 -v -k -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{ "update_id":10000, "message":{"date":1441645532,"chat":{"last_name":"Test Lastname","id":1111111,"first_name":"Test","username":"Test"},"message_id":1365,"from":{"last_name":"Test Lastname","id":1111111,"first_name":"Test","username":"Test"}, "text":"/start"}}' "https://[DOMAIN_OMITTED]/PHP/telWH2.php"
But as I said, the webhook never works.
Any hints? Thank you!

How do I manually POST JSON data with only an ssh connection (no cURL or other utility)

I want to manually POST JSON data using just a keyboard and ssh connection (i.e. without cURL). The cURL functionality I'm trying to replicate which works great is equivalent to:
curl -s -w '\n' -X POST -D - \
-H "Content-type: application/json" \
-d '{"param1":"value1","param2":"value2"}' \
https:///myserver.com/mypath
However, when I connect manually:
openssl s_client -connect myserver.com:443 -quiet
and then enter
POST /mypath HTTP/1.1
Host: myserver.com
Content-type: application/json
Accept: application/json
{
"param1": "value1",
"param2": "value2"
}
I get the message "Json content error HV000116: The object to be validated must not be null." I've tried every variation I can think of with whitespace, and encoding, but I still get the error. I know I'm missing something simple, but what is it?
Doh! Just needed to add the Content-length header and everything worked

How to send a large message to api.telegram.org

I'm having trouble sending large messages via bot telegrams. During the search for the problem, I threw off all the extra binding and tested it with curl.
In the case of sending a message with text up to about 1500, everything works, I sent it like this:
curl -s -X POST https://api.telegram.org/bot<ТОКЕН>/sendMessage -d chat_id = <ID_CHATA> -d text = "1100ertyikgnfdhgmcndgbtowewerttysadasdsasadsadddssasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsas "asadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsadsasasadsasasadsasasadsasasadsasasadsadsasasadsadsasasadsadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasasadsas"
In the case of sending a large message, it stops working, in this case I send a text of 2200 characters in size:
curl -s -X POST https://api.telegram.org/bot<ТОКЕН>/sendMessage -d chat_id = <ID_CHATA> -d text = "2200ertyikgnfdhgmcndgbtowewerttysadasdsasadsadddssasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsas asadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasertyikgnfdhgmcndgbtowewerttysadasdsasadsadddssasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasas adsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsadsasasadsadsasasadsadsasasadsasasadsasasadsasasadsasasadsasasadsasasasasasasasasasasasadsasasadsasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsas
Using the -vvvvvv switch for curl, I saw the following details: In the first case (when the message is small and sending is triggered) I see:
Expect: 100-continue HTTP / 1.1 100 Continue HTTP / 1.1 200 OK
In the second case (when I send a large message and the sending does not work) I see:
Expect: 100-continue HTTP / 1.1 100 Continue Empty reply from server Connection #0 to host api.telegram.org left intact Closing connection #0
There seems to be an error in the second CURL request. the -d param requires a string;
curl -s -X POST https://api.telegram.org/bot<ТОКЕН>/sendMessage -d "chat_id=<ID_CHATA>" -d "text='200ertyikgnfdhgmcndgbtowewe'"
Also you close the string before the last char, curl doesn't like that;
" sasasasasasasasasasasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsas
If I edit your second command to use -d "", I can send it as expected.
Even with a message of 2578 chars works just fine.
Google tels me there is an 4096 UTF8 char limit; Git
Telegram even send an TOO_LONG if the text param is too long ;) So
Edit based on comment;
Full command for bash;
curl -s -X POST https://api.telegram.org/bot123456:abcdefghijk/sendMessage -d "chat_id=123456" -d "text='Test'"
If this does not work for you, please show the error you receive after running the command

how to access GSA API

I have a Google Search Appliance and am trying to access the API to download the Event Logs. I am using curl through cygwin on the Windows 7 command line.
I am able to get an authentication token using
curl -X POST -d Email=username -d Passwd=password "http://ip.ad.dr.ess:8443/accounts/ClientLogin"
My problem is that when I attempt to retrieve the even logs themselves:
curl -k -X GET -d query=User -H "Content-type: application/atom+xml" -H "Authorization: GoogleLogin Auth=e73265ce254f7c4afbcbee1743a56e81" "http://10.29.5.5:8000/feeds/logs/eventLog"
curl says that it cannot reach the host:
curl: (7) couldn't connect to host
Any help in getting this to work is greatly appreciated.
Check if you can telnet to the IP-address. If you get a timeout there you should check firewalls etc.
C:\> telnet 10.29.5.5 8000
This looks like a more generic network problem than a problem with either the GSA or Curl.
The problem turned out to be the configuration with my GSA. The GSA is configured to require communication over HTTPS. Because all GSAs default to HTTP traffic over port 8000 and HTTPS traffic over 8443, my problem was solved by sending the following:
curl -k -X GET -d query=User -H "Content-type: application/atom+xml" -H "Authorization: GoogleLogin Auth=e73265ce254f7c4afbcbee1743a56e81" "https://ip.ad.dr.ess:8443/feeds/logs/eventLog"

Does nginx strip custom request headers?

In my nginx.conf I have this line in my server {} section:
log_format debug 'header: "$http_x_myapp" cookies: "$http_cookie"';
Then if I do
curl -H "X_MYAPP:test" -H "COOKIE:yay" localhost
I get something like this in my access log:
header: "-" cookies: "yay"
Does anyone know why nginx is throwing away the X_MYAPP header?
Oops... I'm stupid.
curl -H "X-MYAPP:test" -H "COOKIE:yay" localhost
works... stupid underscores...
The correct way to send cookies with curl is with the -b options:
curl -b 'yay' http://localhost

Resources