我打了一個URL以阿拉伯語參數值(如下圖所示):發送阿拉伯語通過HTTP崗位作爲參數不工作
http://62.215.226.164/fccsms_P.aspx?UID=something&P=somethingS=InfoText&G=96567771404&M=اخص شقث غخع خن ؤخةث&L=E
它完美;我用阿拉伯語在電話上收到消息。但是,當我嘗試通過以下代碼實現相同的功能時,我只在郵件中收到問號。
public void sendSms(SendSms object)
throws MalformedURLException, ProtocolException, IOException
{
String message = new String(object.getMessage().getBytes(), "UTF-8");
System.out.println(message); // This also prints only question marks
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();
}
要在阿拉伯語中獲得消息,需要在代碼中添加或更改什麼?
請[不要問同樣的問題兩次(https://stackoverflow.com/questions/39729307 /如何到手柄阿拉伯語中的Java)。 – VGR