Posting to socket using curl

The name of the pictureThe name of the pictureThe name of the pictureClash 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:



  1. I post XML to login to a system.

  2. Return message contains authentication token.

  3. 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.







share|improve this question






















  • 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














up vote
1
down vote

favorite












I'm struggling to get curl and socat to play nicely together.
The situation is the following:



  1. I post XML to login to a system.

  2. Return message contains authentication token.

  3. 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.







share|improve this question






















  • 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












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:



  1. I post XML to login to a system.

  2. Return message contains authentication token.

  3. 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.







share|improve this question














I'm struggling to get curl and socat to play nicely together.
The situation is the following:



  1. I post XML to login to a system.

  2. Return message contains authentication token.

  3. 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.









share|improve this question













share|improve this question




share|improve this question








edited Jan 15 at 15:43

























asked Jan 15 at 15:34









Shiunbird

284




284











  • 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 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










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.






share|improve this answer




















  • 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










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















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






























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.






share|improve this answer




















  • 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














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.






share|improve this answer




















  • 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












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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










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
















  • 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












 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)