如何在 ASP.NET 中通过 POST 发送重音字符?

发布于 2024-12-16 23:08:06 字数 798 浏览 1 评论 0原文

我想知道如何通过 POST 方法发送 ASP.NET 中的 UTF-8 编码字符。

在我的代码中,它可以工作,但不能使用重音字符(如 ô、ê、é è)。我收到错误 500(内部服务器错误)

在 php 中,我使用函数 utf8_encode() 和 urlencode() 之后,它正在工作!

谢谢您的帮助

这是我的代码:

WebRequest request = WebRequest.Create("http://api.website.com");
request.Method = "POST";
string postData = "login=xxx&password=xxx&postblog=My message. Problem with accented characters like ô ê é è ";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
...
response.Close();

I would like to know how to send via POST method, UTF-8 encoded characters in ASP.NET.

With my code, it's working but not with accented characters (like ô, ê, é è). I receive an Error 500 (internal server error)

In php, I use the functions utf8_encode() and after urlencode() and it's working !

Thank you for you help

Here my code :

WebRequest request = WebRequest.Create("http://api.website.com");
request.Method = "POST";
string postData = "login=xxx&password=xxx&postblog=My message. Problem with accented characters like ô ê é è ";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
...
response.Close();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦回旧景 2024-12-23 23:08:06

不确定是否是这样,但您的 ContentType 不太正确。试试这个

request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"; 

Not sure if this is it, but your ContentType isn't quite correct. Try this

request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文