我想以以下格式从我的 JAVA 应用程序发送 SMS:
名称:客户名称
ConfNO:1234
日期:2012-05-15
NoOfPax:7
由于我使用外部短信网关,我需要将其作为 URL 从应用程序发布。当我收到短信时,我看不到换行符,而是显示文本 \n。请帮助。我的代码是
String senderid = "SMSALERT";
String to = "97112345678";
String text = "Reservation INFO\nName:Customer Name\nConfNO: KN1234\nTime: 12:00PM\n#Pax:5\nThank You for Choosing US";
String type = "text";
String ppgHost = "www.yahoo.com";
String username = "username";
String password = "password";
String datetime = "2012-05-15 12:00:00";
String path = "index.php";
try {
HttpClient httpClient = new DefaultHttpClient();
List<NameValuePair> qparams = new ArrayList<NameValuePair>();
qparams.add(new BasicNameValuePair("username", username));
qparams.add(new BasicNameValuePair("password", password));
qparams.add(new BasicNameValuePair("senderid", senderid));
qparams.add(new BasicNameValuePair("to", to));
qparams.add(new BasicNameValuePair("text", text));
qparams.add(new BasicNameValuePair("type", type));
qparams.add(new BasicNameValuePair("datetime", datetime));
URI uri = URIUtils.createURI("http", ppgHost, -1, path, URLEncodedUtils.format(qparams, "UTF-8"), null);
HttpPost httppost = new HttpPost(uri);
System.out.println(httppost.getURI());
HttpResponse response = httpClient.execute(httppost);
System.out.println(response.getStatusLine());