English 中文(简体)
用浮标出的陶器,装有LINE BREAKS,使用java
原标题:posting url with string parameter that contains LINE BREAKS using java
  • 时间:2012-05-15 13:24:41
  •  标签:
  • java

i want to sent SMS from my JAVA APPLICATION in the following format:
NAME: Customer Name
ConfNO: 1234
Date: 2012-05-15
NoOfPax: Seven
Since i am using external sms gateway i need to post it as URL from the application. When i recive the SMS i dont see line breaks instead the text display . Please help.My Code is

String senderid = "SMSALERT";
    String to = "97112345678";
    String text = "Reservation INFO
Name:Customer Name
ConfNO: KN1234
Time: 12:00PM
#Pax:5
Thank 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());    
最佳回答

如果有URL,你可以使用新行的百分率编码值,则<0D%0A。 虽然%0A (ASCII 10 - line food)或%0D (ASCII 13 - transport Return)应当独自工作。

问题回答

All the parameters needs to be URL encoded. Further, it is a good practice to user system line separator rather than hardcoding " "

System.getProperty (“line.separator”);





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签