0

I have a problem to send a POST request with a text file and some key=value (value contains special characters and it needs to be encoded, e.g: query=select c + a % b).

I've tried like this and it returns error Warning: You can only select one HTTP request!

curl -F "file=@path_to_text_file" 
--data-urlencode "query=select c + a % b" "http://localhost:8082/app"

remove --data-urlencode then it can run but the value of query is not encoded.

I prefer to not need to encode query manually.

6
  • Possible duplicate of What is the right way to POST multipart/form-data using curl? Commented Feb 9, 2018 at 16:49
  • @DmitriChubarov these topics only contain key=value which doesn't have the special characters. Commented Feb 9, 2018 at 16:51
  • The accepted answer at stackoverflow.com/a/19148720/1328439 should solve it for you. To encode the query string use urllib.urlencode() Commented Feb 9, 2018 at 16:56
  • @DmitriChubarov this is not what I wanted to use an external tool to encode, thanks though. Commented Feb 9, 2018 at 17:00
  • 1
    You can specify exactly one content-type for one POST request. It can be either application/x-www-form-urlencoded, or multipart/form-data or text/plain but you have to use only one. For your command curl was complaining that you are trying to specify both form-urlencoded and multipart/form-data. Commented Feb 9, 2018 at 17:07

1 Answer 1

1

This will do the upload then send the post request

curl -F "file=@path_to_text_file" "http://localhost:8082/app" --next --data-urlencode "query=select c + a % b" "http://localhost:8082/app"

Sign up to request clarification or add additional context in comments.

1 Comment

unfortunately, the --next parameter only exists since version 7.36. In Centos 7, it is version 7.29 only.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.