How to UTF-8 encode a string?

N

Nick Hounsome

There is a serious documentation issue with the static encoding properties:

BOM and exception handling are undefined and therefore these properties are
not usable without firstly investigating their actual behaviour and secondly
taking it on faith that MS wont change it.

1) The documentaion should state what these are set to.
2) There should be properties to show these settings.
3) The documentation should state that they are readonly (in fact all
documentation should state the default value for all properties but it
rarely does)

In the absense of documentation the only easily maintainable way to go is to
always create your own using UTF8Encoding(bool,bool). The cost should be
trivial.
 
J

Jon Skeet [C# MVP]

jens said:
this is a B2B scenario and i may not publish the complete System.Net.Trace
as it contain very confidential info.

But here is the last bit . I doubt you can get any usefull hint from it.

Well, I don't know:
System.Net Error: 0 : [8036] Exception in the
HttpWebRequest#4878312::EndGetResponse - The remote server returned an
error: (401) Unauthorized.

That seems to indicate your problem is to do with authorization more
than anything else.

Jon
 
J

jens Jensen

Another question if remote end is a webservice, why can't you make web
reference to it and then communicate via stub?

This is no proper webserivce. It just does xml over https.
 
V

Vadym Stetsyak

Hello, jens!

jJ> This is no proper webserivce. It just does xml over https.

As Jon pointed out, the problem you have is connected with authorization.

Look at the docs for
HttpWebRequest.Credentials property.
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
J

Joerg Jooss

Thus wrote Mike,
I am presuming that the problem is that the bytes are correct but the
remote service doesn't recognize them as being UTF-8. Try adding

req.ContentEncoding = encoding;

That's HttpRequest as of ASP.NET fame and doesn't apply here ;-)
 
J

Joerg Jooss

Thus wrote Mike,
What type is "req", then?

You came up with that line of code, you tell me ;-)

Must have been System.Net.HttpWebRequest -- don't have the OP at hand anymore.

Cheers,
 
M

Mike Schilling

Joerg Jooss said:
Thus wrote Mike,


You came up with that line of code, you tell me ;-)
Must have been System.Net.HttpWebRequest -- don't have the OP at hand
anymore.

The OP didn't show the declaration, which is why I asked.

But I'm sure you (and Jon) are right.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top