處理阿拉伯語我需要阿拉伯值的字符串傳遞給HttpURL作爲參數,但我之前說的,當我打印信息的只顯示問號如何用Java
public void sendSms(SendSms object) throws MalformedURLException,ProtocolException,IOException {
String message=new String(object.getMessage().getBytes(), "UTF-8");
System.out.println(message);//printing only question marks
}
,甚至當我以url參數發送消息,不發送原始消息爲阿拉伯語,發送問號。
public void sendSms(SendSms object) throws MalformedURLException, ProtocolException,IOException {
String message=new String(object.getMessage().getBytes(), "UTF-8");
System.out.println(message);
PrintStream out = new PrintStream(System.out, true, "UTF-8");
out.print(message);
String charset="UTF-8";
URL url = new URL("http://62.215.226.164/fccsms_P.aspx");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestProperty("Accept-Charset", charset);
con.setRequestMethod("POST");
//con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("Accept-Language", "en-US,en,ar_KW;q=0.5");
con.setRequestProperty("Content-Type", "text/html;charset=utf-8");
String urlParameters = "UID=test&P=test&S=InfoText&G=965"+object.getPhone()+"&M= Hello "+object.getName()+" "+message+" &L=A";
// Send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + urlParameters);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
}
的可能的複製[打印阿拉伯語Ø r在System.out其他字符集](http://stackoverflow.com/questions/16644247/print-arabic-or-other-charset-in-system-out) –
@YoungMillie問題中提到我不只需要打印阿拉伯語。在轉換爲「utf-8」之後打印阿拉伯文只是一個測試 –
System.out.println會在Windows命令窗口中將您的字符顯示爲'?',但這並不意味着它們實際上是問號字符。這只是意味着命令窗口不能顯示實際的字符。 – VGR