This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes JSP and the fly likes Unicode problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Unicode problem" Watch "Unicode problem" New topic
Author

Unicode problem

Fouad Fares
Ranch Hand

Joined: Apr 16, 2003
Posts: 38
Hello,

I'm trying to send HTTP request to an sms provoder.
This request contains arabic text. The result of this arabic text is rubbish text.

Could you please advise me how can i set the unicode on my java request.
NB : I'm developping this program under Oracle Jdeveloper JDK 2 version 1.3

import java.sql.*;
import java.util.*;
import oracle.jdbc.driver.*;
import java.util.Vector;
import java.lang.String;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.*;
import java.io.*;
import java.net.URL;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.util.Properties;
import org.w3c.dom.*;
import java.lang.Integer;
import javax.swing.JOptionPane ;
import oracle.jdeveloper.html.*;
import javax.servlet.*;
import javax.servlet.http.*;
import oracle.jdbc.driver.*;
import oracle.xml.sql.query.OracleXMLQuery;
import java.lang.*;
import Jcls_Reuters_Divers.*;

...

URL csoftURL = new URL("http://...");
HttpURLConnection connection = (HttpURLConnection)csoftURL.openConnection();

String postBody = "Username=" + URLEncoder.encode(SMSID) + "&" +
"PIN=" + URLEncoder.encode(SMSPIN) + "&" +
"SendTo=" + URLEncoder.encode(s_mobile) + "&" +
"Message=" + URLEncoder.encode(s_return) + "&" +
"ReplyTo=" + URLEncoder.encode(SMSREPLYTO) + "&" +
"ResponseFormat=1";

connection.setRequestMethod("POST");
connection.setRequestProperty("content-type","utf-8");

// poster les param�tres
connection.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write(postBody);
wr.flush();
wr.close();

// Avoir les r�sultats
connection.connect(); // throws IOException
int responseCode = connection.getResponseCode(); // 200, 404, etc
String responseMsg = connection.getResponseMessage(); // OK, Forbidden, etc

BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));

String oneline = "NULL";
div.WriteLog("debut SMS ");
while ( (oneline = br.readLine()) != null) {
WriteLog(oneline);
if (oneline.toUpperCase().indexOf("ACCEPTED") > 0)
{
InsertLog
}
}

Regards
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unicode problem
 
Similar Threads
error while submitting an http web request
HTTPS Post Request through the URL
Peculiar HTML Form INPUT Tag
POST data with a file upload
httpurlconnection usage