0

I unable to use put method to send data to particular link.. Please find below the code.Let me know if i have to make any change

public class test {
    private static String url = "http://semldvw0728.google.net/.svc/web/testrequests/";
    private static String urlconnection;

    public static void main(String[] args) throws IOException {

    StringBuffer xmlString = new StringBuffer();

    xmlString.append("<TestRequest>");
    xmlString.append("<DateRequested>2011-12-20</DateRequested>");
    xmlString.append("<DemCapID>893467</DemCapID>");
    xmlString.append("<DemCapVersion>1</DemCapVersion>");
    xmlString.append("<IBIS_ID>13530</IBIS_ID>");
    xmlString.append("<ProjectName>LTS</ProjectName>");
    xmlString.append("<RequestedBy>ktmq331</RequestedBy>");
    xmlString.append("<SampleNumber>SN1033645061</SampleNumber>");
    xmlString.append("<Status>Sample Ordered</Status>");
    xmlString.append("</TestRequest>");

    System.out.println("xmlString :" + xmlString.toString());
    url = url + 893467;
    System.out.println("URL : " + url);

    try {
        System.out.println("URL : " + url);
        HttpClient client = new HttpClient();
        PutMethod putMethod = new PutMethod(url);
        client.setConnectionTimeout(8000);
        putMethod.setRequestBody(xmlString.toString());
        System.out.println("statusLine>>>" + putMethod.getStatusLine());
        System.out.println("statusLine>>>"+           putMethod.getResponseBodyAsString());
        putMethod.releaseConnection();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
1
  • Be more specific. Add more information. What is the problem? Is there an error? etc... Commented Dec 20, 2011 at 20:36

1 Answer 1

1

I think you need to make a call to execute, or you could use the HttpClient object you've created to call this.

So maybe add this line after you're setting the request body for your putMethod...

client.executMethod(putMethod);
Sign up to request clarification or add additional context in comments.

4 Comments

Could you please explain me how to create HttpClient
I added how you would call given the code you've provided and linked you to the docs. That should be sufficient.
@user1042983: HttpClient client = new DefaultHttpClient();
I've just updated to point out you should put the line after you set your request body; not after setting the timeout on the client as I originally said.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.