I have no idea, how to send some text using HTTPCLIENT (java // apache) library. I need to send parameters by text to server. Any idea?
Assume you have some-remote-server
as your remote server address and some-servlet
as your remote servlet which accepts param1
, param2
etc.. with its respective values on request. If the remote servlet accept GET call you can use below to send the request;
HttpClient httpClient = new HttpClient();
GetMethod getMethod = new GetMethod(); //You could use PostMethod if servlet accept POST
String request ="http://some-remote-server/some-servlet?param1=value1¶m2=value2";
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
getMethod.setURI(new URI(request, false, null));
...
And then recieve the response return from the remote servlet like this;
ObjectInputStream ois = new ObjectInputStream(getMethod.getResponseBodyAsStream());
ois.readObject();
If you can change the tool, try RestClient Tool for eclipse. It has great support for testing restful web-services. It has option to specify,
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.