Java HttpClient changing content-type?

前端 未结 2 1657
挽巷
挽巷 2020-12-09 14:01

I am building a small app for my Android phone to forward text messages to a webserver using a very basic REST interface.

I am using the android 4.0.3 SDK. I develo

相关标签:
2条回答
  • 2020-12-09 14:42

    easy :

    import org.apache.http.client.methods.HttpPost;
    
    httppost.setEntity(new StringEntity(json.toString(), org.apache.http.entity.ContentType.APPLICATION_JSON));
    
    0 讨论(0)
  • 2020-12-09 14:48

    Change this:

    StringEntity se = new StringEntity(json); 
    se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
    httppost.setEntity(se);
    

    To this only:

    httppost.setEntity(new StringEntity(json.toString(), HTTP.UTF_8));
    
    0 讨论(0)
提交回复
热议问题