【问题标题】:How to set Encoding to Http Post request android如何将编码设置为Http Post请求android
【发布时间】:2013-09-26 14:02:04
【问题描述】:

如何将UTF 编码设置为Http Post 请求?

这是我的代码 sn-p。

HttpClient httpClient = getNewHttpClient();

    String user_agent = (String) httpClient.getParams().getParameter(
            CoreProtocolPNames.USER_AGENT)
            + " Android";
    httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT,
            user_agent);
    httpClient.getParams().setBooleanParameter(
            "http.protocol.expect-continue", false);
    HttpResponse response;
    HttpPost post = new HttpPost(remoteUrl);
    System.out.println("Url:" + remoteUrl + "  values:"
            + nameValuePair.toString());
    post.setEntity(new UrlEncodedFormEntity(nameValuePair));


    response = httpClient.execute(post);
    int postStatus = response.getStatusLine().getStatusCode();
    String result = EntityUtils.toString(response.getEntity());
    System.out.println("result:" + result);

【问题讨论】:

    标签: android character-encoding http-headers


    【解决方案1】:

    您可以通过调用设置任何标题 post.setHeader("HEADER NAME","HEADER VALUE");

    在你的情况下应该是

    post.setHeader("Accept-Charset","utf-8");

    【讨论】:

    • 它适用于这个 request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
    猜你喜欢
    • 2017-03-10
    • 2013-08-07
    • 1970-01-01
    • 2012-07-10
    • 2016-09-28
    • 1970-01-01
    • 2016-12-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多