Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Utilizing curl via HTTPClient  RSS feed

sanchit dua
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The following curl is working in Windows Environment

curl --user --form file=@Testing.csv <URL>/data

But when I'm trying to introduce the commons HTTPClient 4.x for this request, I'm facing the error:

HTTP/1.1 500 Server Error

From the code snippet I'm passing the file and its value inside the BasicNameValuePair. So, whenever I'm passing nothing like
new BasicNameValuePair("file", "")
the response is coming
200 Ok
and obviously the content over the server gets replaced with Empty data.

I got one success in passing the content in Text (the CSV received content) by using StringEntity like
httpPost.setEntity(new StringEntity("a, b, c, d", "UTF-8"));
, but its again giving me 2 thoughts:

1. If I try to use the Text - I mostly face the Java Heap Space issue.
2. I'm not able to pass the FileName from inside StringEntity - like
new StringEntity("file=@Testing.csv")

Please let me know what I'm doing wrong.

This is the following code I'm using:

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!