aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes string getting converted to ASCII Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "string getting converted to ASCII" Watch "string getting converted to ASCII" New topic
Author

string getting converted to ASCII

Reddy Anoop
Greenhorn

Joined: Aug 22, 2007
Posts: 8
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

Joined: Oct 29, 2001
Posts: 8707
    
    6

What do you suppose URLEncoder.encode does?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39544
    
  27
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?


Ping & DNS - updated with new look and Ping home screen widget
Reddy Anoop
Greenhorn

Joined: Aug 22, 2007
Posts: 8
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
Marshal

Joined: Mar 22, 2005
Posts: 39544
    
  27
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
 
subject: string getting converted to ASCII
 
Similar Threads
sendRedirect fails to post data along with url if the data is too large
XML Request using HttpClient
SSL xml encoding
Concatenating string texts based of key value
http://xml.apache.org/axis/ HttpErrorCode:401