How to include an '&' character in a bash curl statement

前端 未结 7 1196
萌比男神i
萌比男神i 2020-11-28 09:14

I\'m trying to use curl in bash to download a webpage, but the & symbol in the URL isn\'t interpreted as a character as I would like. Any ideas on how I can

相关标签:
7条回答
  • 2020-11-28 09:25

    Putting the entire URL inside double quotes should take care of your problem.

    0 讨论(0)
  • 2020-11-28 09:28

    Putting single quotes around the & symbol seems to work. That is, using a URL like http://www.example.com/page.asp?arg1=${i}'&'arg2=${j} with curl returns the requested webpage.

    0 讨论(0)
  • 2020-11-28 09:32

    You can use %26 instead &. The entity code will work fine.

    0 讨论(0)
  • 2020-11-28 09:35

    Instead of trying the escape "&" characters, you can specify http url parameters in POST requests with -d parameter as shown below:

    curl -X POST http://www.example.com \
    -d arg1=this \
    -d arg2=that
    

    If the request is a GET, then you should also add -G option, which tells curl to send the data with GET request.

    curl -X GET -G http://www.example.com \
    -d arg1=this \
    -d arg2=that
    
    0 讨论(0)
  • 2020-11-28 09:41

    Use the parameter --url with double quotes worked for me

    0 讨论(0)
  • 2020-11-28 09:43

    easiest way :

    curl -X GET -G http://example.com -d var1=$1 -d var2=$2
    
    0 讨论(0)
提交回复
热议问题