How to POST URL in data of a curl request

前端 未结 2 1854
执念已碎
执念已碎 2021-02-01 02:30

I am trying to post two parameters using curl, path and fileName:

curl --request POST \'http://localhost/Service\' --data          


        
相关标签:
2条回答
  • 2021-02-01 02:39

    Perhaps you don't have to include the single quotes:

    curl --request POST 'http://localhost/Service' --data "path=/xyz/pqr/test/&fileName=1.doc"
    

    Update: Reading curl's manual, you could actually separate both fields with two --data:

    curl --request POST 'http://localhost/Service' --data "path=/xyz/pqr/test/" --data "fileName=1.doc"
    

    You could also try --data-binary:

    curl --request POST 'http://localhost/Service' --data-binary "path=/xyz/pqr/test/" --data-binary "fileName=1.doc"
    

    And --data-urlencode:

    curl --request POST 'http://localhost/Service' --data-urlencode "path=/xyz/pqr/test/" --data-urlencode "fileName=1.doc"
    
    0 讨论(0)
  • 2021-02-01 02:58

    I don't think it's necessary to use semi-quotes around the variables, try:

    curl -XPOST 'http://localhost/Service' -d "path=%2fxyz%2fpqr%2ftest%2f&fileName=1.doc"
    

    %2f is the escape code for a /.

    http://www.december.com/html/spec/esccodes.html

    Also, do you need to specify a port? ( just checking :) )

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