C#/Restsharp:HTTP 错误 417 预期失败
C#/Restsharp: HTTP Error 417 Expectation failed
我有这个代码:
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: Expectation failed, even System.Net.ServicePointManager.Expect100Continue = false
你能帮帮我吗?谢谢
将上面的 XML 代码放在我的解决方案中的每个 App.config
中很有帮助。
<system.net>
<settings>
<servicePointManager expect100Continue="false" />
</settings>
</system.net>
我从来没有用过 RestSharp,直到我用它来完成一个新项目。
StatusCode = ExpectationFailed
所以这是 417 期望失败错误。太糟糕了,排除故障并不那么容易。
问题是 connectionstring 在 machine.config 中丢失(项目未使用 web.config / app.config 有几件事)
为我修好。
我有这个代码:
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: Expectation failed, even System.Net.ServicePointManager.Expect100Continue = false
你能帮帮我吗?谢谢
将上面的 XML 代码放在我的解决方案中的每个 App.config
中很有帮助。
<system.net>
<settings>
<servicePointManager expect100Continue="false" />
</settings>
</system.net>
我从来没有用过 RestSharp,直到我用它来完成一个新项目。
StatusCode = ExpectationFailed
所以这是 417 期望失败错误。太糟糕了,排除故障并不那么容易。
问题是 connectionstring 在 machine.config 中丢失(项目未使用 web.config / app.config 有几件事)
为我修好。