I am trying to send arabic sms (or french sms) from kannel and it does not get the client end perfectly ( somtimes ?????? for arabic words),
after doing some analysis on the values sent between the bearebox,smsbox and smsc i found out that the error in encoding happens between my bearbox and smsbox.
I have used charset=utf-8&coding=2 on my http request for sending sms but the same problem occurs
Does anyone have any idea on what is the problem or better a solution ??
here is the code i use to send sms
StringBuffer param = new StringBuffer()
param.append("http://localhost:1025/cgi-bin/sendsms?")
param.append(URLEncoder.encode("username","UTF-8")).append("=").append(URLEncoder.encode("xxx","UTF-8"))
param.append("&").append(URLEncoder.encode("password","UTF-8")).append("=").append(URLEncoder.encode("xxxx","UTF-8"))
param.append("&").append(URLEncoder.encode("to","UTF-8")).append("=").append(URLEncoder.encode(numTel,"UTF-8"));
param.append("&").append(URLEncoder.encode("charset","UTF-8")).append("=").append(URLEncoder.encode("utf-8","UTF-8"))
param.append("&").append(URLEncoder.encode("coding","UTF-8")).append("=").append(URLEncoder.encode("2","UTF-8"))
param.append("&").append(URLEncoder.encode("text","UTF-8")).append("=").append(URLEncoder.encode(text,"UTF-8"))
param.append("&").append(URLEncoder.encode("priority","UTF-8")).append("=").append(URLEncoder.encode(""+priority,"UTF-8"))
param.append("&").append(URLEncoder.encode("dlr-mask","UTF-8")).append("=").append(URLEncoder.encode("31","UTF-8"))
param.append("&").append(URLEncoder.encode("dlr-url","UTF-8")).append("=").append(URLEncoder.encode(urlString,"UTF-8"))
try{
URL url = new URL(param.toString())
System.out.println("INFO : Opening connection ")
HttpURLConnection urlconnection = (HttpURLConnection) url.openConnection()
System.out.println("INFO : Connection openned")
BufferedReader input = new BufferedReader( new InputStreamReader(urlconnection.getInputStream()))
String inputLine
while ((inputLine = input.readLine()) != null)
aResult.append(inputLine)
input.close()
}catch(Exception e){
e.printStackTrace()
return false
}
System.out.println("response : "+aResult.toString())
System.out.println("INFO : all sent disconnect.")
'
Thank you
i have been able to send arabic/french sms with this http request example :
StringBuffer param = new StringBuffer()
param.append("http://localhost:1025/cgi-bin/sendsms?")
param.append(URLEncoder.encode("username","UTF-8")).append("=").append(URLEncoder.encode("xxx","UTF-8"))
param.append("&").append(URLEncoder.encode("password","UTF-8")).append("=").append(URLEncoder.encode("xxxx","UTF-8"))
param.append("&").append(URLEncoder.encode("to","UTF-8")).append("=").append(URLEncoder.encode(numTel,"UTF-8"));
param.append("&").append(URLEncoder.encode("coding","UTF-8")).append("=").append(URLEncoder.encode("2","UTF-8"))
param.append("&").append(URLEncoder.encode("text","UTF-8")).append("=").append(URLEncoder.encode(text,"UTF-8"))
param.append("&").append(URLEncoder.encode("priority","UTF-8")).append("=").append(URLEncoder.encode(""+priority,"UTF-8"))
param.append("&").append(URLEncoder.encode("dlr-mask","UTF-8")).append("=").append(URLEncoder.encode("31","UTF-8"))
param.append("&").append(URLEncoder.encode("dlr-url","UTF-8")).append("=").append(URLEncoder.encode(urlString,"UTF-8"))
try{
URL url = new URL(param.toString())
System.out.println("INFO : Opening connection ")
HttpURLConnection urlconnection = (HttpURLConnection) url.openConnection()
System.out.println("INFO : Connection openned")
BufferedReader input = new BufferedReader( new InputStreamReader(urlconnection.getInputStream()))
String inputLine
while ((inputLine = input.readLine()) != null)
aResult.append(inputLine)
input.close()
}catch(Exception e){
e.printStackTrace()
return false
}
System.out.println("response : "+aResult.toString())
System.out.println("INFO : all sent disconnect.")
i don't send the "charset" parameter in my request i only send the coding parameter
I've made a bit of research, and I believe that if you specify coding=2 Kannel expects the message body encoded as UTF-16, at least if I understood correctly this discussion.
Also you should have a look at this document.
All you have to do is the following (kannel release 1.5):
1- Add alt-charset="UTF-8" under smsc group in your kannel configuration
2- when sending the sms مرحبا for example you have to type type the following in your sendsms command: text=مرحبا&charset=UTF-8&coding=1
Check your database using mysql command because database management tools like webmin may not recognize Arabic letters
Related
I am doing an desktop application using Java that can send SMS to a multiple phone numbers via browser. To send the SMS, I need to put in parameters that username, password, message to be sent and the recipient's number.
I have used this and it worked but the problem is it opens up a browser to every recipient so it is not advisable especially if its going to be sent to a lot:
Runtime rt = Runtime.getRuntime();
String url = String.format("http://www.companysms.com/RemoteAPI/SendSMS.aspx?username=%s&encoding=url&password=%s&messagedata=%s&receiver=%s&binary=0", txtUsername.getText(),txtPassword.getText(), txtMessage.getText(),tblMessage.getValueAt(i, 2));
rt.exec("rundll32 url.dll,FileProtocolHandler "+ url);
I have tried this one too but it gives me the HTTP response code 400:
HttpURLConnection connection = (HttpURLConnection) myURL.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder results = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
results.append(line);
}
connection.disconnect();
If I use the URLencoder with "UTF-8", it makes it worse because i cant be sure of what the message the user will send and if they will use any of the special characters. Is there a way to have the first set of codes that I used to not open browser after sending the SMS or is there another way of doing this? Any help is appreciated. Thanks!
i have this command:
wget -O prova.csv --header="prova-user: guest" --header="prova-passwd: guest"
"http://www.....................80&albedo=0.2&horizon=1"
i want to do a batch scheduled in Java but I can not connect. When I try to take the imputstream return me this error:
ERROR message -8: Unregistered IP address
This is my piece of code:
URL myURL = new URL(url);
HttpURLConnection myURLConnection = (HttpURLConnection)myURL.openConnection();
String userCredentials = "guest:guest";
String basicAuth = "Basic " + new String(new Base64().encode(userCredentials.getBytes()));
myURLConnection.setRequestProperty ("Authorization", basicAuth);
myURLConnection.setRequestMethod("POST");
myURLConnection.setRequestProperty("Content-Language", "en-US");
myURLConnection.setUseCaches(false);
myURLConnection.setDoInput(true);
myURLConnection.setDoOutput(true);
// Show page.
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(myURLConnection.getInputStream(), "UTF-8"));
for (String line; ((line = reader.readLine()) != null);) {
System.out.println(line);
}
} finally {
if (reader != null) try { reader.close(); } catch (IOException ignore) {}
}
is it possible? and how can I do it?
Thanks in advance
You had provided 2 completely different commands.
The first is a wget that send in HTTP headers a sort of authentication infos, and GET a result.
The second is a java program that perform an HTTP request in POST with basic authentication.
If the first command is working, than you should forget about the basic authentication and set the proper HTTP headers as you did in the wget command.
I don't know why you try a POST, if the wget looks as a normal GET request.
Just use a GET request in java too.
And it should work.
About the error, I suppose is the server that sent you such error message.
So it could be as you haven't correctly authenticated.
But it is a strange error, I'm expecting such kind of error if the server have a white list of IP addresses allowed to connect.
Are you running the wget and the java code on the same server?
I am trying to get users machine ipAddress using java from my server.
I used the following code, and it works fine in local.
URL url = new URL("http://www.geoplugin.net/json.gp?jsoncallback=?");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
BufferedReader in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
}
}
Using this class, response shows the ip in my local web app.(localhost:8080/myApp/getIp)
I deployed this war to my AWS server, and tried to run the servlet. But this always shows the AWS ip address only. (myIp:8080/myApp/getIp)
It doesn't shows my machine IP.
What was mistake in my code, can someone assist in this?
ServletRequest.getRemoteAddr() OR
getRemoteHost() and getRemotePort()
should returns details of the actual client
If you wanna get client ip i.e. user accessing your web-app through browser, then you can use (client-side-script)javascript to do so. Below is simple example for the same.
function show(response) {
console.log(response);
var html = 'Something went wrong !';
if (200 == response.geoplugin_status) {
html = 'Got your ip as: ' + response.geoplugin_request;
}
document.getElementById('ip').innerHTML = html;
}
var script = document.createElement('script');
script.async = true;
script.src = 'http://www.geoplugin.net/json.gp?jsoncallback=show';
document.getElementById('ip').appendChild(script);
<div id='ip'>Fetching IP ...</div>
I'm having some encoding problems in a Java application that makes HTTP requests to an IIS server.
Iterating over the headers of the URLConnection object I can see the following (relevant) headers:
Transfer-Encoding: [chunked]
Content-Encoding: [utf-8]
Content-Type: [text/html; charset=utf-8]
The URLConnection.getContentEncoding() method returns utf-8 as the document encoding.
This is how my HTTP request, and stream read is being made:
OutputStreamWriter sw = null;
BufferedReader br = null;
char[] buffer = null;
URL url;
url = new URL(this.URL);
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
sw = new OutputStreamWriter(connection.getOutputStream());
sw.write(postData);
sw.flush();
br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF8"));
StringBuilder totalResponse = new StringBuilder();
String line;
while((line = br.readLine()) != null) {
totalResponse.append(line);
}
buffer = totalResponse.toString().toCharArray();
if (sw != null)
sw.close();
if (br != null)
br.close();
return buffer;
However the following string sent by the server "ÃÃÃção" is received by the client as "�����o".
What am I doing wrong ?
Based on your comments, you are trying to receive a FIX message from an IIS server and FIX uses ASCII. There are only a small subset of tags which support other encoding and they have to be treated in a special manner (non-ASCII tags in the standard FIX spec are 349,351,353,355,357,359,361,363,365). If such tags are present, you will get a tag 347 with a value specifying the encoding (for example UTF-8) and then each tag, will be preceded by a tag giving you the length of the coming encoded value (for tag 349, you will always get 348 first with an integer value)
In your case, it looks like the server is sending a custom tag 10411 (the 10xxx range) in some other encoding. By convention, the preceding tag 10410 should give you the length of the value in 10411, but it contains "0000" instead, which may have some other meaning.
Note that although FIX message are very readable, they should still be treated as binary data. Tags and values are mostly ASCII characters, but the delimiter (SOH) is 0x01 and as mentioned above, certain tags may be encoded with another encoding. The IIS service should really return the data as application/octet-stream so it can be received properly. Attempting to return it as text/html is asking for trouble :).
If the server really sends a Content-Encoding of "UTF-8" then it is very confused. See http://svn.tools.ietf.org/svn/wg/httpbis/specs/rfc7231.html#header.content-encoding
For good order a couple of corrections.
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
connection.connect();
try (Writer sw = new OutputStreamWriter(connection.getOutputStream(),
StandardCharsets.UTF_8)) {
sw.write(postData);
sw.flush();
try (BufferedReader br = new BufferedReader(
new InputStreamReader(connection.getInputStream(),
StandardCharsets.UTF_8))) {
StringBuilder totalResponse = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
totalResponse.append(line).append("\r\n");
}
return totalResponse.toString().toCharArray();
} // Close br.
} // Close sw.
Maybe:
postData = ... + "Accept-Charset: utf-8\r\n" + ...;
Receiving the totalResponse.toString() you should have all read correctly.
But then when displaying again, the String/char is again converted to bytes, and there the encoding fails. For instance System.out.println will not do as probably the Windows encoding is used.
You can test the String by dumping its bytes:
String s = totalResponse.toString();
Logger.getLogger(getClass().getName()).log(Level.INFORMATION, "{0}",
Arrays.toString(s.getBytes(StandardCharsets.UTF_8)));
In some rare cases the font will not contain the special characters.
Can you try by putting the stream as part of request attribute and then printing it out on client side. a request attribute will be received as is withou any encoding issues
I want to HTTP GET the server ,read the data and then again do HTTP GET or POST over same socket connection.
However I am unable to get a response for second request.What can be wrong with following code :
Socket s = new Socket(InetAddress.getByName("xyz.abc.asd"), 80);
InputStream is=s.getInputStream();
OutputStream os=s.getOutputStream();
PrintWriter pwGET = new PrintWriter(os);
pwGET.println("GET /login/ HTTP/1.1");
pwGET.println("Host: xyz.abc.asd");
pwGET.println("Connection: keep-alive");
pwGET.println("");
pwGET.flush();
BufferedReader brGET = new BufferedReader(new InputStreamReader(is));
String t=null;
while((t = brGET.readLine()) != null) {
System.out.println(t);
}
pwGET.println("GET /login/ HTTP/1.1");
pwGET.println("Host: xyz.abc.asd");
pwGET.println("Connection: keep-alive");
pwGET.println("");
pwGET.flush();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
t=null;
while((t = br.readLine()) != null) {
System.out.println(t);
}
The main error is, that you don't parse the response correctly.
The response consists of an HTTP header followed by the body (maybe). To get the body you must parse and understand the response header, especially the code (some codes don't have a body), Transfer-Encoding and Content-length. Then you should also have a look at the Connection header.
Only then you know the length of the body and if further requests are accepted on this connection.
Apart from that lines should be delimited by \r\n, not just \n as you do with println.
In summary: if you really want to implement HTTP on your own study the necessary documentation (RFC2616 or the newer RFC7230..RFC7235). If you don't like this use existing HTTP libraries.