Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

string getting converted to ASCII

 
Reddy Anoop
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I am calling a servlet by passing XML data.

Sample xml that I am passing:


data1 =
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TestServlet SYSTEM "http://www.123.com:80/dtds/200703v1.dtd">
<TestConfig generatedDate="31 Oct 2007 16:27:30 GMT" dtdVersion="200703v1" qualification="false">
<MemoryModule mfgPartNum="501-6242" displaySequence="1000"/>
</TestConfig>

String line = URLEncoder.encode("data", "UTF-8") + "=" + URLEncoder.encode(data1, "UTF-8");

when I print the variable line, it prints ASCII values.
data=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22utf-8%22%3F%3E%3C%21DOCTYPE+Configuration+SYSTEM+
%22http%3A%2F%2Fwww.123.com%3A80%2Fdtds

I wanted to send the xml as it is, can anyone please advise how to do this.

Regards
Anoop

[ UD: added linebreak ]
[ November 14, 2007: Message edited by: Ulf Dittmer ]
 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you suppose URLEncoder.encode does?
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks as if you are trying to send it as a GET request (otherwise there would be no need to use URLEncoder.encode). Is there a particular reason you don't want to use POST?
 
Reddy Anoop
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using POST. Here is the code that I have. The servlet accepts a varible called "data" that has the complete xml. Please suggest.
Regards



String str = "";
String line = "";
String data1 = "";
// Send data
URL url = new URL(" http://xx123.test:80/translate");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr =
new OutputStreamWriter(conn.getOutputStream());
BufferedReader br =
new BufferedReader(new InputStreamReader(blb.getBinaryStream()));

while ( (str = br.readLine())!=null)
{
data1 += str; //strBuffer.append(str); }
line = URLEncoder.encode("data", "UTF-8") + "=" +
URLEncoder.encode(data1, "UTF-8");
System.out.println(line);

wr.write(line);
wr.flush();

// Get the response
BufferedReader rd =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = rd.readLine()) != null) {
result.append(line);
}
wr.close() ;
rd.close();
}
catch (Exception e) {
e.printStackTrace(); // should do real exception handling
}
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suggest what? Joe already pointed out that you should not be using URLEncoder.encode.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic