Search code examples
androidhttp-put

Using put request


I am try httpPut method.I don't know how to do it. I am trying this sample.

In log I am getting a very long trace.. Can I know what does this line means??

Http Response:org.apache.http.message.BasicHttpResponse@5273e44c what does this means??

Here is my code

public class AndroidHTTPRequestsActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Creating HTTP client
    HttpClient httpClient = new DefaultHttpClient();


    HttpPut httpPut=new HttpPut("http://www.google.com");

    // Creating HTTP Post
  //        HttpPost httpPost = new HttpPost("http://www.example.com/login");

    // Building post parameters
    // key and value pair
    List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);
    nameValuePair.add(new BasicNameValuePair("email", "user@gmail.com"));
    nameValuePair.add(new BasicNameValuePair("message",
            "Hi, trying Android HTTP post!"));

    // Url Encoding the POST parameters
    try {
        httpPut.setEntity(new UrlEncodedFormEntity(nameValuePair));
    } catch (UnsupportedEncodingException e) {
        // writing error to Log
  //            e.printStackTrace();
    }

    // Making HTTP Request
    try {
        HttpResponse response = httpClient.execute(httpPut);

        // writing response to log
        System.out.println("Http Response:" +response.toString());
        Log.d("Http Response:", response.toString());
     } catch (ClientProtocolException e) {
        // writing exception to log
  //            e.printStackTrace();
     } catch (IOException e) {
        // writing exception to log
  //            e.printStackTrace();

    }
    }
   }

Solution

  • try this for geeting response:

            HttpEntity httpEntity = null;
            httpEntity = response.getEntity();
            response = EntityUtils.toString(httpEntity);