This is my code that works perfectly to post one object to my server.
//Creating HttpPost object
HttpPost post_request = new HttpPost();
//Creating BasicHttpParams
BasicHttpParams params = new BasicHttpParams();
//Setting parameters to params
params.setParameter("json", j);
//Setting params to post_request
post_request.setParams(params);
//setting HttpPost object URI
post_request.setURI(website);
//executing actual request
HttpResponse response = client.execute(post_request);
What I would like to do is to pass two objects as the parameters as so:
//Creating HttpPost object
HttpPost post_request = new HttpPost();
//Creating BasicHttpParams
BasicHttpParams params = new BasicHttpParams();
//Setting parameters to params
params.setParameter("json", j, "json2", j2);
//Setting params to post_request
post_request.setParams(params);
//setting HttpPost object URI
post_request.setURI(website);
//executing actual request
HttpResponse response = client.execute(post_request);
Of course, that does not work. I get a red line underneath setParameter.
What can I do to pass through two objects in my post? I’ve read some varying answers like “it’s not possible and I would have to import a .jar file”, but I feel like there is some easy way I’m missing. Thanks in advance.
Instead of:
Just call
See the javadoc for what you’re calling to understand why this is. http://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/params/BasicHttpParams.html