gpt4 book ai didi

java - 使用java发布带有包含换行符的字符串参数的url

转载 作者:搜寻专家 更新时间:2023-10-31 08:12:32 24 4
gpt4 key购买 nike

我想用以下格式从我的 JAVA 应用程序发送短信:
姓名:客户姓名
session 号:1234
日期:2012-05-15
人数:七个
由于我使用的是外部短信网关,因此我需要将其作为应用程序的 URL 发布。当我收到 SMS 时,我没有看到换行符,而是文本显示\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());

最佳答案

如果它是一个 URL,你可以使用百分比编码值换行,它是 %0D%0A 尽管 %0A(ASCII 10 - 换行)或者%0D(ASCII 13 - 回车)应该单独工作。

关于java - 使用java发布带有包含换行符的字符串参数的url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10601672/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com