How to capture Curl output to a file?

前端 未结 7 1072
小蘑菇
小蘑菇 2020-12-12 08:57

I have a text document that contains a bunch of URLs in this format:

URL = \"sitehere.com\"

What I\'m looking to do is to run curl -K

相关标签:
7条回答
  • 2020-12-12 09:06

    There are several options to make curl output to a file

     # saves it to myfile.txt
    curl http://www.example.com/data.txt -o myfile.txt
    
    # The #1 will get substituted with the url, so the filename contains the url
    curl http://www.example.com/data.txt -o "file_#1.txt" 
    
    # saves to data.txt, the filename extracted from the URL
    curl http://www.example.com/data.txt -O 
    
    # saves to filename determined by the Content-Disposition header sent by the server.
    curl http://www.example.com/data.txt -O -J 
    
    0 讨论(0)
  • 2020-12-12 09:07

    For a single file you can use -O instead of -o filename to use the last segment of the URL path as the filename. Example:

    curl http://example.com/folder/big-file.iso -O
    

    will save the results to a new file named big-file.iso in the current folder. In this way it works similar to wget but allows you to specify other curl options that are not available when using wget.

    0 讨论(0)
  • 2020-12-12 09:07

    If you want to store your output into your desktop, follow the below command using post command in git bash.It worked for me.

    curl https://localhost:8080 --request POST --header "Content-Type: application/json" -o "C:\Desktop\test.txt"

    0 讨论(0)
  • 2020-12-12 09:08
    curl -K myconfig.txt -o output.txt 
    

    Writes the first output received in the file you specify (overwrites if an old one exists).

    curl -K myconfig.txt >> output.txt
    

    Appends all output you receive to the specified file.

    Note: The -K is optional.

    0 讨论(0)
  • 2020-12-12 09:09

    A tad bit late, but I think the OP was looking for something like:

    curl -K myfile.txt --trace-asci output.txt
    
    0 讨论(0)
  • 2020-12-12 09:13

    For those of you want to copy the cURL output in the clipboard instead of outputting to a file, you can use pbcopy by using the pipe | after the cURL command.

    Example: curl https://www.google.com/robots.txt | pbcopy. This will copy all the content from the given URL to your clipboard.

    0 讨论(0)
提交回复
热议问题