I created a webservice using servlet and tomcat 6.0. I created sample java application to call the web service and its working fine. i need to send some data while calling web service. I created in java application as follows
StringEntity zStringEntityL = new StringEntity(zAPIInputStringP.toString());
zStringEntityL.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,
"application/json"));
HttpParams aHttpParamsL = new BasicHttpParams();
HttpProtocolParams.setVersion(aHttpParamsL, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(aHttpParamsL, HTTP.UTF_8);
SchemeRegistry aSchemeRegistryL = new SchemeRegistry();
aSchemeRegistryL.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
ClientConnectionManager ccm = new ThreadSafeClientConnManager(aHttpParamsL, aSchemeRegistryL);
DefaultHttpClient client = new DefaultHttpClient(ccm, aHttpParamsL);
HttpPost aHttpPostL = new HttpPost(URL + zAPIName);
aHttpPostL.setHeader("Authorization", "Basic");
aHttpPostL.setEntity(zStringEntityL);
HttpResponse aHttpResponseL;
aHttpResponseL = client.execute(aHttpPostL);
Here “zAPIInputStringP” is my data in JSON format.
In webservice how i need to get those data? I checked in debug mode in eclispe, i cant able to find it.
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
//How to get data?
}
Please help me out.
When you send the data to a servlet via post method, the data is available via input stream. Following is how your post method should look like.
You JSON string is contained in
zAPIInputStringP.