Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Utilizing curl via HTTPClient

 
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 abc@xyz.com:testing --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:



 
Let nothing stop you! Not even this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!