作者martone (Krel)
看板java
标题[问题] 请问一个编码问题
时间Thu Sep 25 17:52:23 2008
C#
public void HttpPost(string uri)
{
Encoding encode = Encoding.GetEncoding("utf-8");
WebRequest req = WebRequest.Create(uri);
string postData = "test=大家好";
byte[] bytes = encode.GetBytes(postData);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = bytes.Length;
Stream sendStream = req.GetRequestStream();
sendStream.Write(bytes, 0, bytes.Length);
sendStream.Close();
}
Servlet NETBEANS预设
protected void processRequest(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
try {
System.out.println(request.getParameter("test"));
} finally {
out.close();
}
}
----------------------------------------------------------------
为了能传中文给servlet,因此C#使用ENCODE来转码,而结果却不然…
在C#中(给行动装置使用)的写法应该是很正确的,却发生传值给Servlet时
在Console中所印出的文字都是 ?????????
请问在这二个地方中,是否有我需要改进的地方呢? 谢谢各位了^^"
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.170.5.102
1F:推 TonyQ:request.setCharset? 09/25 18:23
2F:推 PsMonkey:对阿... 跟 response 比较没关系吧 @_@ 09/25 18:51
3F:→ martone:谢谢两位^^" 09/25 19:33