• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

string getting converted to ASCII

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you suppose URLEncoder.encode does?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suggest what? Joe already pointed out that you should not be using URLEncoder.encode.
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic