日期:2014-05-18  浏览次数:20815 次

请问我用HttpURLConnection来post到http上去后,手机收到中文及中文后就空的了,请问是什么原因?
URL   url   =   null;
                HttpURLConnection   httpurlconnection   =   null;
PrintWriter   out   =   response.getWriter();
                try   {
String   tel   = "1375117989 ";
String   content   =   "第一搜股网! ";
                        url   =   new   URL( "http://www.wwww.com/ww.php ");
                        httpurlconnection   =   (HttpURLConnection)url.openConnection();
                        httpurlconnection.setDoOutput(true);
                        httpurlconnection.setRequestMethod( "POST ");
httpurlconnection.setRequestProperty( "Cache-Control ",   "private ");
httpurlconnection.setRequestProperty( "Accept-Charset ",   "gb2312 ");
httpurlconnection.setRequestProperty( "Content-Type ",   "application/x-www-form-urlencoded ");  
                        String   username   =   " <?xml   version= '1.0 '   encoding= 'UTF-8 '?> <SmsSubmitReq> <from   value= ' "+tel+ " '/> <to   value= ' "+tel+ " '/> <feeType   value= 'test '/> <gid   value= '1 '/> <linkid   value= ' '/> <charset   value= 'UTF-8 '/> <data> sanyou2312三忧14243 </data> </SmsSubmitReq> ";
httpurlconnection.getOutputStream().write(username.getBytes());
                        httpurlconnection.getOutputStream().flush();
                        httpurlconnection.getOutputStream().close();
                        int   code   =   httpurlconnection.getResponseCode();

//最后手机收到只有sanyou2312,请问如何解决?
我用xmlhttp方式post就不会有这种情况。

------解决方案--------------------
有点意思,研究一下~~~
------解决方案--------------------
改成:
httpurlconnection.getOutputStream().write(username.getBytes( "UTF-8 "));

试一下