i have a test server running on port 3062, i want to send it HTTP POST data using curl

when i run the following command :

curl -d '{"k1":"v1","k2","v2"}' -X POST http://localhost:3062

it works fine i get the response

but when i run the following:

sudo curl -d '{"k1":"v1","k2","v2"}' -X POST http://localhost:3062

i get: 301 and a redirect page

I cannot remove the sudo as the curl command is part of a much larger script that requires it.

  • 3
    I don't suppose you're using a proxy in an environment variable, and the server at 3062 requires users to come from the proxy? sudo could be dropping the variable. – Jeff Schaller Mar 7 at 15:06
  • @JeffSchaller i am using proxy env' variable, how do i run sudo so it does not drop env variables ? – Mike Mar 7 at 15:16
  • I'm honestly very surprised, but my kneejerk reaction would be to modify the curl call to explicitly use a proxy with the --proxy command-line option. – Jeff Schaller Mar 7 at 15:18
  • @JeffSchaller sadly i cannot modify the script, thanks for the direction though, ill see how i can configure sudo to recognize same env' – Mike Mar 7 at 15:20
  • I will suggest unix.stackexchange.com/a/13246/117549 as the (duplicate) answer to the problem. (translate HOME to your proxy variable) – Jeff Schaller Mar 7 at 15:21

As to Jeff Schaller response i checked online, indeed sudo cleans env' variables

in order to preserve env' variables need to run sudo -E

once i ran with this, it worked great

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.