Kong / unirest-java

Unirest in Java: Simplified, lightweight HTTP client library.
http://kong.github.io/unirest-java/
MIT License
2.58k stars 591 forks source link

Only in kong unirest i can't submit form using post request #442

Closed rzkrn20 closed 2 years ago

rzkrn20 commented 2 years ago

I'm trying to submit a form using post request, i try this on postman, using unirest mashape & okhttp, and it works. But, not in kong unirest, the response i got is the html of the web itself. When i use postman/mashape/okhttp, I got the same response when i delete the submit field.

Is there something wrong with my code?

HttpResponse<String> response = Unirest.post(url)
  .field("number", "1")
  .field("type", "DATA")
  .field("comment", "Test")
  .field("submit", "Submit")
  .field("file", new File("/C:/Users/User/Documents/Test.pdf"))
  .asString();

Expected behavior Get a success response

ryber commented 2 years ago

I don't understand how this would work in anything "1 and etc" isn't a valid URL.

Without knowing what the url expects I don't know what you need to change. There is nothing wrong with the code itself (other than the URL)

rzkrn20 commented 2 years ago

I'm sorry, i can't write the url for some reasons. it's my fault i didn't write it clear, but it's actually a valid url

ryber commented 2 years ago

Without knowing the exact requirements of the "API" you are accessing it's impossible to know what aspect of this is different. It's not the goal of Unirest to behave exactly like Postman (or x) as all things may be "helpful" in different ways. But in this case Unirest is going to produce a properly segmented multipart/form-data request. You would have to ask the API owner what the requirements are