看板 java 關於我們 聯絡資訊
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
TonyQ:request.setCharset? 09/25 18:23
PsMonkey:對阿... 跟 response 比較沒關係吧 @_@ 09/25 18:51
martone:謝謝兩位^^" 09/25 19:33