Reputation: 457
I'm working on creating sample application which sends a XML file to the local server. In the server side I need to read the data which is sent by client and write it into a new file.
Below is the client side code I'm using to read a XML file and send it to the server.
HttpClient httpclient = new DefaultHttpClient();
// Below code is used to connect with the local tomact server or servlet
HttpPost httppost = new HttpPost("http://xxx.xxx.xxx.xxx:yyyy");
File file = new File("C:\\Files\\sample.xml");
InputStreamEntity reqEntity = new InputStreamEntity(
new FileInputStream(file), -1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(true);
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
int respcode = response.getStatusLine().getStatusCode();
System.out.println("respcode: " + respcode);
Kindly let me know by using tomact how to fetch the data from the client and write it into the server side. Do I need to use servlets to handle this?
I had visited many blogs but I'm not getting how to create a server side code to accomplish this task.
Thanks in advance!
Upvotes: 0
Views: 1146
Reputation: 17622
Yes, you need to write a servlet/filter to handle this. Once your servlet receives the HttpServletRequest
object,
You can read it using HttpServletRequest.getInputStream()
method
Upvotes: 3