| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 
 |  
HttpClient client = new HttpClient();
client.getParams().setParameter("http.useragent", "ServletTest");
//URL sur serveur de test
PostMethod post = new PostMethod("http://www.mondomaine.fr/projet/Servlet");
//Paramétres du POST
NameValuePair[] data = { new NameValuePair("xml", _content_xml) };
post.setRequestBody(data);
BufferedReader br = null;
int returnCode;
try 
{
	returnCode = client.executeMethod(post);
	if(returnCode == HttpStatus.SC_NOT_IMPLEMENTED) 
	{
		System.err.println("The Post method is not implemented by this URI");
		// still consume the response body
		post.getResponseBodyAsString();
	}
	else 
	{
		br = new BufferedReader(new InputStreamReader(post.getResponseBodyAsStream()));
		String readLine;
		while(((readLine = br.readLine()) != null)) 
		{
			System.err.println(readLine);
		}
	}
} catch (HttpException e) {
	e.printStackTrace();
} catch (IOException e) {
	e.printStackTrace();
}
finally {
		post.releaseConnection();
		if(br != null) try { br.close(); } catch (Exception fe) {}
	} | 
Partager