running curl with sudo results in a status code 301 (Moved Permanently)

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















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.










share|improve this question



















  • 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


















0















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.










share|improve this question



















  • 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














0












0








0








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.










share|improve this question
















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.







sudo curl http






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 14:53







Mike

















asked Mar 7 at 14:47









MikeMike

1011




1011







  • 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













  • 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








3




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





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





@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





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





@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






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











1 Answer
1






active

oldest

votes


















0














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






share|improve this answer























    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    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%2f504935%2frunning-curl-with-sudo-results-in-a-status-code-301-moved-permanently%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    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






    share|improve this answer



























      0














      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






      share|improve this answer

























        0












        0








        0







        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






        share|improve this answer













        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 7 at 15:26









        MikeMike

        1011




        1011



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f504935%2frunning-curl-with-sudo-results-in-a-status-code-301-moved-permanently%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay