[問題] 請問一個編碼問題
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
推
09/25 18:23, , 1F
09/25 18:23, 1F
推
09/25 18:51, , 2F
09/25 18:51, 2F
→
09/25 19:33, , 3F
09/25 19:33, 3F