简单 WebClient 不工作:自定义区域性不能通过 LCID 传递,只能通过名称传递
Simple WebClient not working: Customized cultures cannot be passed by LCID, only by name
我正在尝试使用 WebClient 向 URL 发送一个简单的 POST
请求,但我收到
An exception occurred during a WebClient request.
并且在 InnerException 中
Customized cultures cannot be passed by LCID, only by name.
互联网上显然没有关于此异常的讨论。
这是我的代码:
public static void Send(string message)
{
var url = "https://api.mailgun.net/v3/sandbox1ebb54bdb39044988d3c916d833769b7.mailgun.org/messages";
using (var client = new WebClient())
{
client.Credentials = new NetworkCredential("api", "some_password");
var values = new NameValueCollection();
values["from"] = "Mailgun Sandbox <postmaster@sandbox1ebb54bdb39044988d3c916d833769b7.mailgun.org>";
var response = client.UploadValues(url, values);
var responseString = Encoding.Default.GetString(response);
Reader.log(responseString);
}
}
在 client.UploadValues(url, values)
处引发异常
显然,这是旧版 .NET 的一个已知问题(如果您的系统区域设置不是美国)https://connect.microsoft.com/VisualStudio/feedback/details/1741767/compiler-error-customized-cultures-cannot-be-passed-by-lcid-only-by-name
迁移到 .NET 4.0 或更高版本可以解决问题。
我正在尝试使用 WebClient 向 URL 发送一个简单的 POST
请求,但我收到
An exception occurred during a WebClient request.
并且在 InnerException 中
Customized cultures cannot be passed by LCID, only by name.
互联网上显然没有关于此异常的讨论。
这是我的代码:
public static void Send(string message)
{
var url = "https://api.mailgun.net/v3/sandbox1ebb54bdb39044988d3c916d833769b7.mailgun.org/messages";
using (var client = new WebClient())
{
client.Credentials = new NetworkCredential("api", "some_password");
var values = new NameValueCollection();
values["from"] = "Mailgun Sandbox <postmaster@sandbox1ebb54bdb39044988d3c916d833769b7.mailgun.org>";
var response = client.UploadValues(url, values);
var responseString = Encoding.Default.GetString(response);
Reader.log(responseString);
}
}
在 client.UploadValues(url, values)
显然,这是旧版 .NET 的一个已知问题(如果您的系统区域设置不是美国)https://connect.microsoft.com/VisualStudio/feedback/details/1741767/compiler-error-customized-cultures-cannot-be-passed-by-lcid-only-by-name
迁移到 .NET 4.0 或更高版本可以解决问题。