gpt4 book ai didi

c# - 收到此错误 : "The remote server returned an error: (422) Unprocessable Entity." when doing post from C# to RoR

转载 作者:行者123 更新时间:2023-11-30 22:42:06 25 4
gpt4 key购买 nike

此代码用于 outlook 插件。我们正在尝试 POST 到一个页面并收到此错误:

The remote server returned an error: (422) Unprocessable Entity.

C#代码在这里:

webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
Byte[] postData = asciiEncoding.GetBytes("email=e2@email.com&password=hunter2");
char[] resultHTML = asciiEncoding.GetChars(webClient.UploadData("http://url", "POST", postData));
string convertedResultHTML = new string(resultHTML);

知道是什么原因造成的吗?

最佳答案

如果您发送的字符不在 ASCII 范围内,则 POST 数据必须在作为 ASCII 发送出去之前进行编码。你应该尝试这样的事情:

Byte[] postData = asciiEncoding.GetBytes(HttpUtility.UrlEncode("email=e2@email.com&password=hunter2"));

关于c# - 收到此错误 : "The remote server returned an error: (422) Unprocessable Entity." when doing post from C# to RoR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4600494/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com