Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

posting url with string parameter that contains LINE BREAKS using java

Tags:

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 \n. Please help.My Code is

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());    
like image 579
AnithaRaj Avatar asked May 15 '12 13:05

AnithaRaj


People also ask

How do you add a line break in URL?

You can try sending the standard carriage return ("\r") and line feed character ("\n") [line. separator] instead of just "/n". Further, if you can, probably browse through the external sms gateway API docs on how they read a newline character, It may vary from standards.

How do you encode a new line?

The C programming language provides the escape sequences '\n' (newline) and '\r' (carriage return).


1 Answers

If it's a URL you can use the percent-encoded value for a new line, it's %0D%0A although %0A (ASCII 10 - line feed) or %0D (ASCII 13 - carriage return) should work alone.

like image 172
JKirchartz Avatar answered Nov 09 '22 10:11

JKirchartz