如何在HttpPost Android上发单code字发单、如何在、Android、HttpPost

2023-09-05 05:40:53 作者:人間不值得

我试图让我的应用程序,这使得一个HTTP POST上传新的消息的多语言支持。什么我需要做的,为了支持日本和放大器;其他非拉丁语系语言?我的code目前看起来是这样的:

  //注意味精字符串是由它送过来的时候一个JSON消息...
私人字符串doHttpPost(URL字符串,字符串味精)
        抛出异常{

    HttpPost后=新HttpPost(URL);

    StringEntity stringEntity =新StringEntity(MSG);
    post.setEntity(stringEntity);


    返回执行(后);
}
 

解决方案

尝试在StringEntity设置编码:

  StringEntity stringEntity =新StringEntity(MSG,UTF-8);
 

android用volley怎么给服务器发送json

I'm trying to allow multilingual support in my app which makes an HTTP post to upload new messages. What do I need to do in order to support japanese & other non latin based languages? my code currently looks something like this:

    //note the msg string is a JSON message by the time it gets here...
private String doHttpPost(String url, String msg)
        throws Exception {

    HttpPost post = new HttpPost(url);

    StringEntity stringEntity = new StringEntity(msg);
    post.setEntity(stringEntity);


    return execute(post);
}

解决方案

Try setting encoding on StringEntity:

StringEntity stringEntity = new StringEntity(msg, "UTF-8");