Android发送http请求作为unicode无法正常工作

时间:2015-02-19 08:38:28

标签: android http unicode ascii

您好我正在使用android。我正在寻找将一些数据发送到服务器但我必须在UNICODE中发送数据。我在谷歌搜索并找到了#34; HTTP.UTF_8"方法。但它仍然在服务器中收到ASCII值。如何将UNICODE数据发送到服务器。这是我的代码

 String message = "<ENVELOPE>"
    +"<HEADER>"
    +"<VERSION>1</VERSION>"
+"<REQVERSION>1</REQVERSION>"
+"<TALLYREQUEST>Export</TALLYREQUEST>"
+"<TYPE>DATA</TYPE>"
+"<ID>TPGETCOMPANIES</ID>"
+"<SESSIONID>"+SessionID+"</SESSIONID>"
+"<TOKEN>"+String.valueOf(token)+"</TOKEN>"
+"</HEADER>"
+"<BODY>"
+"<DESC>"
+"<STATICVARIABLES>"
+"<SVINCLUDE>Connected</SVINCLUDE>"
+"</STATICVARIABLES>"
+"</DESC>"
+"</BODY>"
+"</ENVELOPE>";


        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("https://dev1.tallyenterprise.com");
        httppost.setHeader("Content-Type", "text/xml; charset=utf-16");
        httppost.setHeader("ID", "TPGETCOMPANIES");
        httppost.setHeader("SOURCE", "EA");
        httppost.setHeader("TARGET", "TNS");
        //Log.d("DEBUG", "HEADERS: " + httppost.getFirstHeader("Authorization: Bearer"));

        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = null;
        try {
            httppost.setEntity(new StringEntity(message,HTTP.UTF_8));   


        //  HttpResponse resp = httpclient.execute(httppost);
       //   HttpEntity ent = resp.getEntity();


            responseBody = httpclient.execute(httppost, responseHandler);

        } catch (ClientProtocolException e) {

            e.printStackTrace();
        } catch (IOException e) {

            e.printStackTrace();
        }

0 个答案:

没有答案