0

I need to send a lot of strings to a web server using Java. I have a List<String> with huge amount of strings and I need to send it via POST request to the Struts2 action on the server side.

I have tried something starting with

HttpPost httppost = new HttpPost(urlStr);

but don't know how to use it.

On other side I have a Struts2 action, and getting the POST request is easy to me.

I think this solution is too close, but it doesn't solve my problem because it's using just one string : HTTP POST using JSON in Java

So, how to send many strings to a server using Java?

Community
  • 1
  • 1
Magno C
  • 1,922
  • 4
  • 28
  • 53
  • 2
    And the question is ..? – Andrea Ligios Jun 30 '14 at 14:36
  • I need to know what is unclear in my question and why my comment was deleted. – Magno C Jun 30 '14 at 21:52
  • As you can see, I'm not one of the closers, nor the downvoter, nor the flagger of the comment. But 1) The comment was deleted because someone flagged it, probably because you were yelling. Don't use CAPITALIZED STRINGS TO SAY WHAT YOU WANT TO SAY because it is against netiquette and SO rules in general, and since you are asking, 2) you may find useful to read [Jon Skeet's advices](http://msmvps.com/blogs/jon_skeet/archive/2010/08/29/writing-the-perfect-question.aspx) on how to ask a question in the best way. I voted for reopening too, btw. Take it easy, cheers. – Andrea Ligios Jul 01 '14 at 11:59
  • Netiquette does not forbid to capitalize. I do this when I realy need to scream or make me clear. You was sarcastic when asking "what is the question" when all I've done was to forget the question mark in title. The question body is crystal clear, so Roman C understood it and reply with perfection straight to point. I hope you moderators keeps this comment just as my explanation. I don't want to start a controversy as my question is already answered. Cheers. – Magno C Jul 01 '14 at 16:11

1 Answers1

2

You should do somthing

HttpPost httppost = new HttpPost(url);
List<NameValuePair> params = new ArrayList<>();
for(String s : list) 
  params.add(new BasicNameValuePair("param", s));
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse response = httpclient.execute(httppost);

on the other side is an action mapped to the url has setter for param. It should be List<String> or String[]. The action when intercepted will populate that param property.

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • Thanks for you answer. It's just what I need to know. Is my question "unclear" for you? – Magno C Jun 30 '14 at 21:52
  • Nop, I will assist to reopen your question, I don't know why they closed it. I think a problem you have not `?` sign in the body of it ;) – Roman C Jul 01 '14 at 09:02
  • I forgot. The best thing to do is to correct the post, as I've done with others many times, instead vote to close. – Magno C Jul 01 '14 at 15:58
  • Yes, that's right, but it depends on editor capabilities to make a good suggestion. Reviewers mostly don't understand a question details and often make a decision by subjective factor implied by a common pattern. If you are fun of SO spend some time on meta and reviewer chain to understand those patterns that make your post with better quality and protect your post by quality posting. Don't worry, your question will be reopen soon. And have a good day! – Roman C Jul 01 '14 at 17:54