MyException - 我的异常网
当前位置:我的异常网» Java Web开发 » 请教我用HttpURLConnection来post到http上去后,手

请教我用HttpURLConnection来post到http上去后,手机收到中文及中文后就空的了,请教是什么原因

www.MyException.Cn  网友分享于:2013-12-24  浏览:34次
请问我用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 "));

试一下

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有