473,467 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Encoding Question

I try to write a ASP.Net web application which will post data to other
websites

I'm use NameValueCollection class add(...) method and WebClient class
uploadvalue(...) method to post data to other website. It works fine if
the data is in English, however, when it contain characters in other
languages (such as Chinese big5), it will display some un-readable
characters.

In web.config file I set encoding to "big5"
<globalization fileEncoding="big5" requestEncoding="big5"
responseEncoding="big5" />

In aspx page html I set codePage to "950"
<%@ Page Language="vb" validateRequest="false" AutoEventWireup="false"
Codebehind="message_post.aspx.vb" Inherits="message_post.WebForm1"
codePage="950" %>

If anyone knows how to solve this problem, please let me know .. Thanks ..
Nov 19 '05 #1
1 1640
Soda wrote:
I try to write a ASP.Net web application which will post data to other
websites

I'm use NameValueCollection class add(...) method and WebClient class
uploadvalue(...) method to post data to other website. It works fine
if the data is in English, however, when it contain characters in
other languages (such as Chinese big5), it will display some
un-readable characters.

In web.config file I set encoding to "big5"
<globalization fileEncoding="big5" requestEncoding="big5"
responseEncoding="big5" />

In aspx page html I set codePage to "950"
<%@ Page Language="vb" validateRequest="false" AutoEventWireup="false"
Codebehind="message_post.aspx.vb" Inherits="message_post.WebForm1"
codePage="950" %>

If anyone knows how to solve this problem, please let me know ..


<globalization /> has no effect on WebClient. WebClient.UploadValues() in
..NET 1.1 always uses UTF-8 internally. If you want to use a different
encoding like Big5, you'll need to use WebRequest or WebClient.UploadData(),
and perform the encoding manually:

public void UploadValues(string url, NameValueCollection data, string
encoding) {
Encoding enc = Encoding.GetEncoding(encoding);
StringBuilder builder = new StringBuilder();
foreach (string name in data) {
string encodedName = HttpUtility.UrlEncode(name, enc);
string encodedValue = HttpUtility.UrlEncode(data[name], enc);
builder.Append(encodedName);
builder.Append('=');
builder.Append(encodedValue);
builder.Append('&');
}
builder.Remove(builder.Length - 1, 1);
byte[] bytes = Encoding.ASCII.GetBytes(builder.ToString());
WebClient client = new WebClient();
client.Headers["Content-Type"] = String.Format(
"application/x-www-form-urlencoded; charset={0}",
encoding);
byte[] response = client.UploadData(url, bytes);
// Do something with the response...
}

Cheers,

--
Joerg Jooss
www.joergjooss.de
ne**@joergjooss.de
Nov 19 '05 #2

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

Similar topics

2
by: Mark | last post by:
Sorry about the last... Anyway, here's the question: I've been working on some C# routines to process strings in and out of various encodings. The hope is that I can just let the user type in...
7
by: polarz | last post by:
I wrote a front end to a command line mp4 music tagger that reads my playlist files and gets info such as artist, title, album, etc, etc. I use the info to catalog, tag, sort, etc, my files. I've...
5
by: Waldy | last post by:
Hi there, how do you set the encoding format of an XML string? When I was outputting the XML to a file you can specify the encoding format like so: XmlTextWriter myWriter; myWriter = new...
4
by: Christina | last post by:
Hey Guys, Currently, I am using the below code: Dim oReqDoc as XmlDocument Dim requiredBytes As Byte() requiredBytes = System.Text.UTF8Encoding.UTF8.GetBytes(oReqDoc.InnerXml). Here, I am...
4
by: George | last post by:
Hi, I am puzzled by the following and seeking some assistance to help me understand what happened. I have very limited encoding knowledge. Our SAP system writes out a text file which includes...
4
by: Provost Zakharov | last post by:
Hello, I just needed some help on how the DOM is encoded by the IE parser. As per the MSDN page, http://msdn.microsoft.com/workshop/author/dhtml/reference/charsets/charset4.asp ,server encodings...
3
by: mortb | last post by:
1. How do I determine which encoding a xmldocument or xmlreader uses when opening a document? I'm not just talking about the <?xml encoding="utf-8"?attribute, but the actual encoding of the...
23
by: Allan Ebdrup | last post by:
I hava an ajax web application where i hvae problems with UTF-8 encoding oc chineese chars. My Ajax webapplication runs in a HTML page that is UTF-8 Encoded. I copy and paste some chineese chars...
1
by: ujjwaltrivedi | last post by:
Hey guys, Can anyone tell me how to create a text file with Unicode Encoding. In am using FileStream Finalfile = new FileStream("finalfile.txt", FileMode.Append, FileAccess.Write); ...
0
by: deloford | last post by:
Hi This is going to be a question for anyone who is an expert in C# Text Encoding. My situation is this: I have a Sybase database which is firing back ISO-8559 encoded strings. I am unable to...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.