此代码用于Outlook插件。我们正在尝试发布到页面,并出现此错误:
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 protected]&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 protected]&password=hunter2"));