473,769 Members | 5,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

send utf-8 string http request

I want to submit a utf-8 xml request to a servlet by the following coding.
it seesm that the servlet can't recognize it correctly.

can i just using string postData = "..... utf-8 data" and then save the
files at utf-8 encoded at the vs.net ide?

or if i use string, vs.net ide will conside it to be utf-16???

UTF8Encoding encoding = new UTF8Encoding();
string postData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +

"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"urn:schem as-xmlsoap-org:envelope\"> " +

"<SOAP-ENV:Header>" +

"<SOAPActionVer sion>1.5.5</SOAPActionVersi on></SOAP-ENV:Header>" +

"<SOAP-ENV:Body>" +

"<cmEDMSCustome rContactPage transactionType =\"UPDT\">" +

"<cmEDMSCustome rContactPageSer vice>" +

"<cmEDMSCustome rContactPageHea der PageReadSW=\"fa lse\"
CustomerContact ID=\"8210710493 \"></cmEDMSCustomerC ontactPageHeade r>" +

"<cmEDMSCustome rContactPageDet ails>" +

"<LogEntry> " +

"<LogEntryHeade r CustomerContact ID=\"8210710493 \">" +

"</LogEntryHeader> " +

"<LogEntryR ow rowAction=\"ADD \" CustomerContact ID=\"8210710493 \" LogEntry=\"
utf-8 characters \">" +

"</LogEntryRow>" +

"</LogEntry>" +

"</cmEDMSCustomerC ontactPageDetai ls>" +

"</cmEDMSCustomerC ontactPageServi ce>" +

"</cmEDMSCustomerC ontactPage>" +

"</SOAP-ENV:Body >" +

"</SOAP-ENV:Envelope>";

Console.WriteLi ne(postData);
byte[] data = encoding.GetByt es(postData);
// Prepare web request...

HttpWebRequest myRequest =
(HttpWebRequest )WebRequest.Cre ate(http://172.18.2.1:7520/server);
myRequest.Metho d = "POST";

myRequest.Conte ntType="text/xml";

myRequest.Conte ntLength = data.Length;

myRequest.SendC hunked = true;

myRequest.Trans ferEncoding = "UTF8";
myRequest.Crede ntials = new NetworkCredenti al("CDX", "pwd");

Stream newStream=myReq uest.GetRequest Stream();

// Send the data.

newStream.Write (data,0,data.Le ngth);

newStream.Close ();
Nov 15 '05 #1
7 11988
Mullin Yu <mu*******@ctil .com> wrote:
I want to submit a utf-8 xml request to a servlet by the following coding.
it seesm that the servlet can't recognize it correctly.

can i just using string postData = "..... utf-8 data" and then save the
files at utf-8 encoded at the vs.net ide?

or if i use string, vs.net ide will conside it to be utf-16???

UTF8Encoding encoding = new UTF8Encoding();


<snip>

There's no need to create a new UTF8Encoding - just use Encoding.UTF8.

The rest of your code looks almost correct though. All you need is to
change your content type so it's "text/xml; encoding=UTF-8" so that the
servlet can work out what you've sent it in. It should then be fine.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Jon Skeet [C# MVP] wrote:
Mullin Yu <mu*******@ctil .com> wrote:
I want to submit a utf-8 xml request to a servlet by the following
coding. it seesm that the servlet can't recognize it correctly.
[...] There's no need to create a new UTF8Encoding - just use Encoding.UTF8.


Actually, there is. Encoding.UTF8 adds a BOM, which you definitely don't
want when posting data.

Cheers,

--
Joerg Jooss
jo*********@gmx .net

Nov 15 '05 #3
Mullin Yu wrote:
I want to submit a utf-8 xml request to a servlet by the following
coding. it seesm that the servlet can't recognize it correctly.


What's the exact error?

--
Joerg Jooss
jo*********@gmx .net

Nov 15 '05 #4
Joerg Jooss <jo*********@gm x.net> wrote:
Jon Skeet [C# MVP] wrote:
Mullin Yu <mu*******@ctil .com> wrote:
I want to submit a utf-8 xml request to a servlet by the following
coding. it seesm that the servlet can't recognize it correctly.

[...]
There's no need to create a new UTF8Encoding - just use Encoding.UTF8.


Actually, there is. Encoding.UTF8 adds a BOM, which you definitely don't
want when posting data.


I don't see any evidence of that when using Encoding.UTF8.G etBytes (as
the OP used):

using System;
using System.Text;

class Test
{
static void Main()
{
Console.WriteLi ne (Encoding.UTF8. GetBytes("x").L ength);
}
}

prints 1, rather than 4 which it would print if a BOM were being used.

It uses a BOM if you create a StreamWriter with it though.

Even if you were to want to use a version of UTF8Encoding which didn't
use a BOM, I'd make it a static readonly member of another class rather
than creating a new instance every time you go through the routine.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5
the utf8 chinese character became rubblish at oracle db, but it's ok for the
java program, so that i suspect it's due to my limited knowledge of using
class and method in .net.

how about reading from a utf-8 file, i can read it, but it seems having 6
bytes of byte order marks. am i right?

thanks!
"Joerg Jooss" <jo*********@gm x.net> wrote in message
news:uz******** ******@tk2msftn gp13.phx.gbl...
Mullin Yu wrote:
I want to submit a utf-8 xml request to a servlet by the following
coding. it seesm that the servlet can't recognize it correctly.


What's the exact error?

--
Joerg Jooss
jo*********@gmx .net

Nov 15 '05 #6
Mullin Yu <mu*******@ctil .com> wrote:
the utf8 chinese character became rubblish at oracle db, but it's ok for the
java program, so that i suspect it's due to my limited knowledge of using
class and method in .net.
You need to find out exactly where the characters became "rubbish". The
way to do that is to output them (as unicode numbers rather than
glyphs) at various different points, and check where they go wrong.
how about reading from a utf-8 file, i can read it, but it seems having 6
bytes of byte order marks. am i right?


No, I believe there should only be 3 bytes of BOM: 0xef 0xbb 0xbf.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #7
Jon Skeet [C# MVP] wrote:
Joerg Jooss <jo*********@gm x.net> wrote:
Jon Skeet [C# MVP] wrote:
Mullin Yu <mu*******@ctil .com> wrote:
I want to submit a utf-8 xml request to a servlet by the following
coding. it seesm that the servlet can't recognize it correctly.
[...]
There's no need to create a new UTF8Encoding - just use
Encoding.UTF8.


Actually, there is. Encoding.UTF8 adds a BOM, which you definitely
don't want when posting data.


I don't see any evidence of that when using Encoding.UTF8.G etBytes (as
the OP used):

using System;
using System.Text;

class Test
{
static void Main()
{
Console.WriteLi ne (Encoding.UTF8. GetBytes("x").L ength);
}
}

prints 1, rather than 4 which it would print if a BOM were being used.

It uses a BOM if you create a StreamWriter with it though.


Yeah, got that mixed up.
Even if you were to want to use a version of UTF8Encoding which didn't
use a BOM, I'd make it a static readonly member of another class
rather than creating a new instance every time you go through the
routine.


Sure, but tell it to the original author ;->
--
Joerg Jooss
jo*********@gmx .net
Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
5739
by: Haines Brown | last post by:
I'm having trouble finding the character entity for the French abbreviation for "number" (capital N followed by a small supercript o, period). My references are not listing it. Where would I find an answer to this question (don't find it in the W3C_char_entities document). -- Haines Brown brownh@hartford-hwp.com
8
2232
by: lkrubner | last post by:
I was trying to set a cookie before I called session_start() and it was giving me an error. But isn't sessions really just a cookie? Why would it matter if I sent a cookie before session_start? Can I set them afterwards?
0
2127
by: Todd Price | last post by:
Hello - I'm having no luck sending an email message from an asp page with UTF-8 encoding so that Japanese characters can be correctly rendered. Does anyone know how to do this from asp?
1
6291
by: michi | last post by:
Hi there.... Got here a tricky thing with my SMTP. First I show you what works on my machine.. **This Works** SmtpMail.SmtpServer = "mail.gmx.net" <-gmx is my mail provider SmtpMail.Send"mymail@gmx.net", "somebody@xxx.ch", "sub",
2
1404
by: khng | last post by:
Current, I have a function to send UTF-8 encoded HTML Format email to user. But my found that the produced email sometime accidently being injected with the ! sign....... e.g. <td> sometime become <!td> here is the code for that function
19
7928
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: session_start(): Cannot send session cache limiter - headers already sent in /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSession.php on line 14
6
13892
by: archana | last post by:
Hi all, can someone tell me difference between unicode and utf 8 or utf 18 and which one is supporting more character set. whic i should use to support character ucs-2. I want to use ucs-2 character in streamreader and streamwriter. How unicode and utf chacters are stored.
7
12151
by: Jimmy Shaw | last post by:
Hi everybody, Is there any SIMPLE way to convert from UTF-16 to UTF-32? I may be mixed up, but is it possible that all UTF-16 "code points" that are 16 bits long appear just the same in UTF-32, but with zero padding and hence no real conversion is necessary? If I am completely wrong and some intricate conversion operation needs to take place, can anyone give me some primer on the subject?
5
3233
by: julian.tklim | last post by:
Hi, I am using trying to send out an XML using ASP. It is actually trying to call some webservice application using SOAP. The problem is that the same codes works perfectly fine in Excel VBA on the same server, but when it comes to IIS server, the program stop at "xHTTP.send xDoc.XML" line. It seems like the IIS server refuse to let the XML being sent out using the xHTTP object.
0
2918
by: amar elzaman | last post by:
peace be upon u friends i'm working on a project to send sms through pc and gsm modem(mobile) and every thing is ok, i succeded to send but english sms only, when i tried to send arabic the message sent with errors in encoding the arabic characters. my mobile is nokia n73, it supports these character sets ofencoding UCS2","GSM","PCCP437","PCDN","IRA","HEX","8859-1 this is sample code i entered in the hyper terminal, and surely i...
0
9590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10223
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10000
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8879
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.