0

I know that I am able to add the following to the web.config file in order to achieve what I am trying to achieve.

However, I only want UTF-32 for a single view, not all of them. How can I accomplish this? I know how to do it with my response:

HttpContext.Current.Response.Headers["Content-Type"] += ";charset=utf-32";

But how to do it with my request?

Edit By request, I mean the equivalent to this: http://msdn.microsoft.com/en-us/library/hy4kkhe0.aspx. By specifying that attribute, it's possible to specify a request encoding.

1
  • It's not clear what you are trying to do. Commented Dec 20, 2011 at 12:42

2 Answers 2

2

What did you mean with "how to do it with my request?". Values in Request object are about your clients coming to your site. Do you want to make a server side request to a URL?

If you want to make a server side request you can put value to :

  WebRequest request = WebRequest.Create("domain.com");
  request.ContentType = "application/xxx; charset=utf-32";
  request.GetResponse();

Edit: The values in the Request are determined by clients that request your URL. In the page you share, there is a requestEncoding attribute. But the description of the attribute says that it specifies assumed encoding. But it is clear that any request having Accept-Charset in its Header, simply override your setting. By the way, building any architecture belongs requestEncoding setting is not recommended. If you are developing a multiuser or public application, you may not decide how Request shaped.

You can also do it with UploadData method of WebClient:

WebClient wc = new WebClient();
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
byte[] responseArray = wc.UploadData("URL_TO_POST", System.Text.Encoding.Default.GetBytes("param1_name=param1_value&param2_name=param2_value"));
string responseText = System.Text.Encoding.ASCII.GetString(responseArray);
Sign up to request clarification or add additional context in comments.

4 Comments

That's great. How can I use this as an equivalent to WebClient's UploadValues function?
I edited the answer with WebClient version. But you can set Content-Type parameter when using UploadData method, not UploadValues.
With the new solution, it works fine with UTF8 (but with loss of characters). As soon as I change to UTF32 it gives an error 500 on the server. I tried putting a breakpoint. It doesn't even get to the first line in the controller of that URL.
Mathias.. I answered what you asked first about setting header for Request object. Now you have a different issue about Encoding. Please ask a new question or try to process your project yourself.
1

The encoding of the request is decided by the client - a browser, a call to jQuery ajax(), or some app. The only thing you can do about request encoding is hope that the client performing the call/request has the decency to tell your server about its encoding correctly.

1 Comment

The link that you provided only specifies the assumed encoding for when the client does not tell you what encoding it provides. It is still a fact that it is the client that provides this. Besides, what is the problem that you need to solve?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.