tags:

views:

42

answers:

0

I am using the following example for httpput connection but getting a response as bad request. Please tell me where I am wrong in the following Java code:

String responseXmlString = null;
HttpEntity responseEntity = null;
DefaultHttpClient client = new DefaultHttpClient();

UsernamePasswordCredentials credentials = 
    new UsernamePasswordCredentials("un", "password");
AuthScope authScope = new AuthScope(target.getHostName(), target.getPort());
client.getCredentialsProvider().setCredentials(authScope, credentials);

HttpPut put = new HttpPut("accessurl");

// This section is used for all requests   
put.setEntity(new StringEntity(xml, "UTF-8"));

put.addHeader("Content-Type", "application/xml");
put.addHeader("Accept", "application/xml");
HttpResponse response = client.execute(target, put);
responseEntity = response.getEntity();
responseXmlString = EntityUtils.toString(responseEntity);