Posting to socket using curl

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I'm struggling to get curl and socat to play nicely together.
The situation is the following:
- I post XML to login to a system.
- Return message contains authentication token.
- I post subsequent requests with the token.
Caveat: if the connection is broken, the token expires, so I can't just use plain curl.
It works fine in PowerShell: https://pastebin.com/5Jiw1fct
However, I need this to run in Linux. Since I need the connection to persist, I decided to use socat.
If I run this to POST the XML:
curl http://$target_ip -d @./xml/login.xml
I get a proper answer from the system. But the connection is closed, so I can't re-use the token.
However, if I try this (of course, after socat):
curl --unix-socket /tmp/$target_ip.sock -d @./xml/login.xml
Curl complain I don't have the URL set.
Ideas?
Thanks as always.
curl xml http socat
add a comment |Â
up vote
1
down vote
favorite
I'm struggling to get curl and socat to play nicely together.
The situation is the following:
- I post XML to login to a system.
- Return message contains authentication token.
- I post subsequent requests with the token.
Caveat: if the connection is broken, the token expires, so I can't just use plain curl.
It works fine in PowerShell: https://pastebin.com/5Jiw1fct
However, I need this to run in Linux. Since I need the connection to persist, I decided to use socat.
If I run this to POST the XML:
curl http://$target_ip -d @./xml/login.xml
I get a proper answer from the system. But the connection is closed, so I can't re-use the token.
However, if I try this (of course, after socat):
curl --unix-socket /tmp/$target_ip.sock -d @./xml/login.xml
Curl complain I don't have the URL set.
Ideas?
Thanks as always.
curl xml http socat
Add thesocatcommand you use to your question. It should listen to the domain socket and connect to$target_ip:80. For yourcurlcommand, use the original command and add the--unix-socketoption, i.e. keep thehttp://$target_ippart.
â meuh
Jan 15 at 20:24
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm struggling to get curl and socat to play nicely together.
The situation is the following:
- I post XML to login to a system.
- Return message contains authentication token.
- I post subsequent requests with the token.
Caveat: if the connection is broken, the token expires, so I can't just use plain curl.
It works fine in PowerShell: https://pastebin.com/5Jiw1fct
However, I need this to run in Linux. Since I need the connection to persist, I decided to use socat.
If I run this to POST the XML:
curl http://$target_ip -d @./xml/login.xml
I get a proper answer from the system. But the connection is closed, so I can't re-use the token.
However, if I try this (of course, after socat):
curl --unix-socket /tmp/$target_ip.sock -d @./xml/login.xml
Curl complain I don't have the URL set.
Ideas?
Thanks as always.
curl xml http socat
I'm struggling to get curl and socat to play nicely together.
The situation is the following:
- I post XML to login to a system.
- Return message contains authentication token.
- I post subsequent requests with the token.
Caveat: if the connection is broken, the token expires, so I can't just use plain curl.
It works fine in PowerShell: https://pastebin.com/5Jiw1fct
However, I need this to run in Linux. Since I need the connection to persist, I decided to use socat.
If I run this to POST the XML:
curl http://$target_ip -d @./xml/login.xml
I get a proper answer from the system. But the connection is closed, so I can't re-use the token.
However, if I try this (of course, after socat):
curl --unix-socket /tmp/$target_ip.sock -d @./xml/login.xml
Curl complain I don't have the URL set.
Ideas?
Thanks as always.
curl xml http socat
edited Jan 15 at 15:43
asked Jan 15 at 15:34
Shiunbird
284
284
Add thesocatcommand you use to your question. It should listen to the domain socket and connect to$target_ip:80. For yourcurlcommand, use the original command and add the--unix-socketoption, i.e. keep thehttp://$target_ippart.
â meuh
Jan 15 at 20:24
add a comment |Â
Add thesocatcommand you use to your question. It should listen to the domain socket and connect to$target_ip:80. For yourcurlcommand, use the original command and add the--unix-socketoption, i.e. keep thehttp://$target_ippart.
â meuh
Jan 15 at 20:24
Add the
socat command you use to your question. It should listen to the domain socket and connect to $target_ip:80. For your curl command, use the original command and add the --unix-socket option, i.e. keep the http://$target_ip part.â meuh
Jan 15 at 20:24
Add the
socat command you use to your question. It should listen to the domain socket and connect to $target_ip:80. For your curl command, use the original command and add the --unix-socket option, i.e. keep the http://$target_ip part.â meuh
Jan 15 at 20:24
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
Curl might connect to a Unix socket, but the hostname is required for the HTTP request.
Have you tried setting up socat to listen on 127.0.0.1 and connect to the IP address (not name) of target system, adding the hostname from the url to /etc/hosts with an IP address of 127.0.0.1, then using the unmolested URL in the curl invocation?
I've had some pain in the past with services running on non-standard ports - so if you already have a webserver running then you'll need to use network namespaces or some other magic so that curl and the remote server both think you are connecting to the intended port.
Alternatively you can use the original URL, the socat listening on a non-standard port on lo and specify the --resolve option in curl rather than having to fudge the port and/or add an entry in /etc/hosts (requires curl >=7.57)
While it is very unusual that you have a token tied to the TCP session, it seems even more surprising that this is for an http rather than an https service.
I don't have root access to the machine, so I'm not sure how much of /etc/hosts wizardly I can do. I spoke to our vendor - when they described me their APIs, I was as surprised as you are with the token tied to the session. It's being a royal nightmare to write for it. I don't want to have ending up to install node or so. What I need is super simple, I should not need to write any more than a few lines of bash.
â Shiunbird
Jan 15 at 18:22
Without root access your only choice is the --resolve option. Did you try?
â symcbean
Jan 15 at 19:38
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Curl might connect to a Unix socket, but the hostname is required for the HTTP request.
Have you tried setting up socat to listen on 127.0.0.1 and connect to the IP address (not name) of target system, adding the hostname from the url to /etc/hosts with an IP address of 127.0.0.1, then using the unmolested URL in the curl invocation?
I've had some pain in the past with services running on non-standard ports - so if you already have a webserver running then you'll need to use network namespaces or some other magic so that curl and the remote server both think you are connecting to the intended port.
Alternatively you can use the original URL, the socat listening on a non-standard port on lo and specify the --resolve option in curl rather than having to fudge the port and/or add an entry in /etc/hosts (requires curl >=7.57)
While it is very unusual that you have a token tied to the TCP session, it seems even more surprising that this is for an http rather than an https service.
I don't have root access to the machine, so I'm not sure how much of /etc/hosts wizardly I can do. I spoke to our vendor - when they described me their APIs, I was as surprised as you are with the token tied to the session. It's being a royal nightmare to write for it. I don't want to have ending up to install node or so. What I need is super simple, I should not need to write any more than a few lines of bash.
â Shiunbird
Jan 15 at 18:22
Without root access your only choice is the --resolve option. Did you try?
â symcbean
Jan 15 at 19:38
add a comment |Â
up vote
0
down vote
Curl might connect to a Unix socket, but the hostname is required for the HTTP request.
Have you tried setting up socat to listen on 127.0.0.1 and connect to the IP address (not name) of target system, adding the hostname from the url to /etc/hosts with an IP address of 127.0.0.1, then using the unmolested URL in the curl invocation?
I've had some pain in the past with services running on non-standard ports - so if you already have a webserver running then you'll need to use network namespaces or some other magic so that curl and the remote server both think you are connecting to the intended port.
Alternatively you can use the original URL, the socat listening on a non-standard port on lo and specify the --resolve option in curl rather than having to fudge the port and/or add an entry in /etc/hosts (requires curl >=7.57)
While it is very unusual that you have a token tied to the TCP session, it seems even more surprising that this is for an http rather than an https service.
I don't have root access to the machine, so I'm not sure how much of /etc/hosts wizardly I can do. I spoke to our vendor - when they described me their APIs, I was as surprised as you are with the token tied to the session. It's being a royal nightmare to write for it. I don't want to have ending up to install node or so. What I need is super simple, I should not need to write any more than a few lines of bash.
â Shiunbird
Jan 15 at 18:22
Without root access your only choice is the --resolve option. Did you try?
â symcbean
Jan 15 at 19:38
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Curl might connect to a Unix socket, but the hostname is required for the HTTP request.
Have you tried setting up socat to listen on 127.0.0.1 and connect to the IP address (not name) of target system, adding the hostname from the url to /etc/hosts with an IP address of 127.0.0.1, then using the unmolested URL in the curl invocation?
I've had some pain in the past with services running on non-standard ports - so if you already have a webserver running then you'll need to use network namespaces or some other magic so that curl and the remote server both think you are connecting to the intended port.
Alternatively you can use the original URL, the socat listening on a non-standard port on lo and specify the --resolve option in curl rather than having to fudge the port and/or add an entry in /etc/hosts (requires curl >=7.57)
While it is very unusual that you have a token tied to the TCP session, it seems even more surprising that this is for an http rather than an https service.
Curl might connect to a Unix socket, but the hostname is required for the HTTP request.
Have you tried setting up socat to listen on 127.0.0.1 and connect to the IP address (not name) of target system, adding the hostname from the url to /etc/hosts with an IP address of 127.0.0.1, then using the unmolested URL in the curl invocation?
I've had some pain in the past with services running on non-standard ports - so if you already have a webserver running then you'll need to use network namespaces or some other magic so that curl and the remote server both think you are connecting to the intended port.
Alternatively you can use the original URL, the socat listening on a non-standard port on lo and specify the --resolve option in curl rather than having to fudge the port and/or add an entry in /etc/hosts (requires curl >=7.57)
While it is very unusual that you have a token tied to the TCP session, it seems even more surprising that this is for an http rather than an https service.
answered Jan 15 at 17:23
symcbean
2,22911121
2,22911121
I don't have root access to the machine, so I'm not sure how much of /etc/hosts wizardly I can do. I spoke to our vendor - when they described me their APIs, I was as surprised as you are with the token tied to the session. It's being a royal nightmare to write for it. I don't want to have ending up to install node or so. What I need is super simple, I should not need to write any more than a few lines of bash.
â Shiunbird
Jan 15 at 18:22
Without root access your only choice is the --resolve option. Did you try?
â symcbean
Jan 15 at 19:38
add a comment |Â
I don't have root access to the machine, so I'm not sure how much of /etc/hosts wizardly I can do. I spoke to our vendor - when they described me their APIs, I was as surprised as you are with the token tied to the session. It's being a royal nightmare to write for it. I don't want to have ending up to install node or so. What I need is super simple, I should not need to write any more than a few lines of bash.
â Shiunbird
Jan 15 at 18:22
Without root access your only choice is the --resolve option. Did you try?
â symcbean
Jan 15 at 19:38
I don't have root access to the machine, so I'm not sure how much of /etc/hosts wizardly I can do. I spoke to our vendor - when they described me their APIs, I was as surprised as you are with the token tied to the session. It's being a royal nightmare to write for it. I don't want to have ending up to install node or so. What I need is super simple, I should not need to write any more than a few lines of bash.
â Shiunbird
Jan 15 at 18:22
I don't have root access to the machine, so I'm not sure how much of /etc/hosts wizardly I can do. I spoke to our vendor - when they described me their APIs, I was as surprised as you are with the token tied to the session. It's being a royal nightmare to write for it. I don't want to have ending up to install node or so. What I need is super simple, I should not need to write any more than a few lines of bash.
â Shiunbird
Jan 15 at 18:22
Without root access your only choice is the --resolve option. Did you try?
â symcbean
Jan 15 at 19:38
Without root access your only choice is the --resolve option. Did you try?
â symcbean
Jan 15 at 19:38
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f417264%2fposting-to-socket-using-curl%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Add the
socatcommand you use to your question. It should listen to the domain socket and connect to$target_ip:80. For yourcurlcommand, use the original command and add the--unix-socketoption, i.e. keep thehttp://$target_ippart.â meuh
Jan 15 at 20:24