How can I use curl to simulate a request from Firefox over a proxy?

14,363

Solution 1

I've done this through Firebug.

Once you've installed firebug, follow this steps:

  1. Right-click a webpage inside firefox and choose this option:

enter image description here

  1. Select Net tab

enter image description here

  1. Refresh the page

  2. Right-click the URL request you want to simulate

  3. Choose copy as cURL

enter image description here

  1. The URL request that you want to simulate is now in your clipboard.

Solution 2

You have to specify a proxy otherwise thing would not work, do like:

  1. curl -x 127.0.0.1:8888 "httpS://www.example.com/" — Be sure that you are trying to connect throught HTTPS, otherwise simple get will be sent.
  2. curl -p -x 127.0.0.1:8888 "http://www.example.com/" — That thing will work even with ordinary HTTP resources.

Was hard to find any already existing topics on that subject except for this, so maybe I'm answering an already answered question.

Share:
14,363
merlin2011
Author by

merlin2011

I am a student. A perpetual student. For the convenience of those who Google and copy & paste resulting URL, feel free to try my plugins for Firefox and Chrome. I have recently released my primary project Arachne, a lightning-fast cooperative threading library. Please give it a whirl and create an issue if you see any problems. I have also written a few simple tools, such as one for tmux automation, an improved version of the venerable Unix column, and a tool for adding color to text in the terminal based on user-specified patterns.

Updated on June 05, 2022

Comments

  • merlin2011
    merlin2011 almost 2 years

    In particular, I am attempting to replicate the behavior of firefox when I set it to use a proxy for https traffic.

    From my tests, it appears that Firefox sends a CONNECT request to the proxy, while the following curl command directly sends GET to the proxy.

    curl --proxy-basic mydomain.com:8001 https://www.google.com
    

    How can I make curl behave like firefox for testing purposes with respect to the proxy for HTTPS connections?

    EDIT1: The issue is not with the User-Agent, because I am not trying to fool the proxy into thinking I am firefox, only to help the proxy function the way it would with Firefox.

  • merlin2011
    merlin2011 about 11 years
    I don't think it is just the USERAGENT problem. I am more concerned about lack of CONNECT.
  • merlin2011
    merlin2011 about 11 years
    @DanielStenberg, the proxy is not seeing the CONNECT though, with the command I gave in the question.
  • Daniel Stenberg
    Daniel Stenberg about 11 years
    the command in the question doesn't specify any proxy... see --proxy for that