2012-03-09 15 views
0

私はHttpUrlConnectionを使用してjsonの外に投稿しますが、中国語の文字が?????に変わっているようです。 私はutf-16、big 5のような異なるエンコーディングスタイルで試しましたが、何が原因であるのか理解できません。 これをデバッグすると、投稿前に中国語の文字を見ることができますが、投稿時にそれがなぜ変わるのですか? コード部以下HttpURLConnection出力ストリーム中国語

 String postData,String charset) throws MalformedURLException, IOException{ 
     URL url = new URL(targetUrl); 
     HttpURLConnection connection = (HttpURLConnection) url.openConnection(
                   Proxy.NO_PROXY); 
     connection.setConnectTimeout(postTimeout); 
     connection.setDoOutput(true); 
     connection.setInstanceFollowRedirects(false); 
     connection.setRequestMethod("POST"); 
     connection.setRequestProperty("Content-Type", 
            contentType+"; charset="+charset);//+charset.getName().toUpperCase());//+charset.getName()); 



     sleep(sleepTime); 
     OutputStream os = connection.getOutputStream(); 
     //"UnicodeBigUnmarked" 
//   
//  byte[] bt= postData.getBytes(); 
//  System.out.println(bt); 
//  os.write(bt); 
//  System.out.println(); 
//  os.flush(); 
     //System.out.println(postData); 
     try 
     { 
      Writer writer = new OutputStreamWriter(os, charset); 
      writer.write(postData); 
      writer.flush(); 
      writer.close(); 
     } catch (IOException e) { 
      logger.severe("Http POST exception"); 

     } finally { 
      if (os != null) { 
       os.close(); 
      } 
     } 



     int responseCode = connection.getResponseCode(); 

     connection.disconnect(); 

     return responseCode; 

でIはBIG5、UTF-16、それでも変化なしで試みられています。

ありがとうございました。

答えて

1

私はhere

+0

は素晴らしい:)作業ありがとうございました説明のようにあなたはJSONのUnicodeアスキー・安全な表現を使うべきであると信じています) –

関連する問題