C#/Restsharp:HTTP错误417预期失败
本文关键字:失败 错误 HTTP Restsharp | 更新日期: 2023-09-27 18:00:58
我有这个代码:
System.Net.ServicePointManager.Expect100Continue = false;
RestClient = new RestClient(baseUri);
RestClient.Proxy = new WebProxy("http://proxy.domain.tld:8888");
RestClient.Proxy.Credentials = new NetworkCredential("abc", "abc");
RestClient.CookieContainer = new System.Net.CookieContainer();
// Receive JSESSIONID
var req = new RestRequest("scs/result/resultinfo.jsp", Method.GET);
var res = RestClient.Execute(req); // This request works
// Login
req = new RestRequest("scs/result/j_security_check", Method.POST);
req.AddHeader("Content-Type", "application/x-www-form-urlencoded");
req.AddParameter("j_username", username, ParameterType.GetOrPost);
req.AddParameter("j_password", password, ParameterType.GetOrPost);
res = RestClient.Execute(req); // This request fails
POST请求导致HTTP错误417:预期失败,甚至System.Net.ServicePointManager.Expect100Continue = false
你能帮我吗?谢谢
将上面的XML代码放在我的解决方案中的每个App.config
中会有所帮助。
<system.net>
<settings>
<servicePointManager expect100Continue="false" />
</settings>
</system.net>
我从未使用过RestSharp,直到一个新的项目出现。
StatusCode = ExpectationFailed
这就是417预期失败的错误。遗憾的是,故障排除并不是那么容易。
问题是machine.config中缺少连接字符串(项目没有使用web.config/app.config进行某些操作(
为我修复。