Reputation: 15886
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.
Upvotes: 0
Views: 1247
Reputation: 919
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¶m2_name=param2_value"));
string responseText = System.Text.Encoding.ASCII.GetString(responseArray);
Upvotes: 2
Reputation: 19305
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.
Upvotes: 1