使用 Cookie 发送 POST 个请求
Sending POST requests using Cookies
我想使用以下 POST 通过 WebRequest 发送 POST 请求:
POST https://olui2.fs.ml.com/ClientFederation/LoginValidateUser.asmx/ValidatePassword HTTP/1.1
Host: olui2.fs.ml.com
Connection: keep-alive
Content-Length: 76
Origin: https://olui2.fs.ml.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.103 Safari/537.36
Content-Type: application/json; charset=UTF-8
Cache-Control: no-cache
X-Requested-With: XMLHttpRequest
__PageIdHeader: jclrKnUbxSsmkPo01YGJFc4O9l3kt79RUdjpUT9mB3E=
X-Bear: jclrKnUbxSsmkPo01YGJFc4O9l3kt79RUdjpUT9mB3E=
Accept: */*
Referer: https://olui2.fs.ml.com/login/ConfirmIdentity.aspx
Accept-Encoding: gzip,deflate
Accept-Language: en-US,en;q=0.8
Cookie: pxv=da927b45-fda7-440d-893e-5058b60053b1; __g_u=277817800941577_1_1_1_5_1422571043310_1; __g_c=a%3A0; pxss=392613e3-6d74-4947-b707-8b6ce7a1df8e; FSDSession=true; Bear=jclrKnUbxSsmkPo01YGJFc4O9l3kt79RUdjpUT9mB3E=; NSC_pmvj2-NzNfssjmm-wt=9fea903a0000; pxsq=19
{"username":"username","rememberMe":false,"password":"mypassword","data":null}
{} 用于 JSON。这是我目前的代码:
//Get the variables
string url = "http://olui.fs.ml.com/Login/Login.aspx";
string userName = loginUN;
string userPassword = loginPW;
//Connection Parameters
string method = "POST";
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create("https://olui2.fs.ml.com/ClientFederation/LoginValidateUser.asmx/ValidatePassword");
webReq.Connection = "keep-alive";
webReq.ContentLength = 76;
webReq.UserAgent = " Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.103 Safari/537.36";
webReq.ContentType = "application/json; charset=UTF-8";
webReq.Accept = "*/*";
webReq.Referer = " https://olui2.fs.ml.com/login/ConfirmIdentity.aspx";
我不确定如何设置登录时需要使用的 cookie。其次,在我的 WebRequest
中找不到请求的一些部分,我。 e. Accept-Language、Cache-Control、X-Request 和南方的所有部分。
我不确定的另一件大事是用户名和密码的JSON。
您在一个问题中有多个挑战。也许最好将你的一组问题分成多个问题。
无论如何,我将重点关注您首先提到的 cookie 挑战。 HttpWebRequest
组件有一个 CookieContainer
属性。您需要创建 cookie 容器的实例并将其附加到特定的 属性。示例:
HttpWebRequest webReq = ...
webReq.CookieContainer = new CookieContainer();
webReq.CookieContainer.Add(new Cookie("name", "value", "/", yourDomain));
// etc.
这是一个不错的博客,可能会提供更多帮助:http://blogs.msdn.com/b/adarshk/archive/2004/08/24/219714.aspx
我想使用以下 POST 通过 WebRequest 发送 POST 请求:
POST https://olui2.fs.ml.com/ClientFederation/LoginValidateUser.asmx/ValidatePassword HTTP/1.1
Host: olui2.fs.ml.com
Connection: keep-alive
Content-Length: 76
Origin: https://olui2.fs.ml.com
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.103 Safari/537.36
Content-Type: application/json; charset=UTF-8
Cache-Control: no-cache
X-Requested-With: XMLHttpRequest
__PageIdHeader: jclrKnUbxSsmkPo01YGJFc4O9l3kt79RUdjpUT9mB3E=
X-Bear: jclrKnUbxSsmkPo01YGJFc4O9l3kt79RUdjpUT9mB3E=
Accept: */*
Referer: https://olui2.fs.ml.com/login/ConfirmIdentity.aspx
Accept-Encoding: gzip,deflate
Accept-Language: en-US,en;q=0.8
Cookie: pxv=da927b45-fda7-440d-893e-5058b60053b1; __g_u=277817800941577_1_1_1_5_1422571043310_1; __g_c=a%3A0; pxss=392613e3-6d74-4947-b707-8b6ce7a1df8e; FSDSession=true; Bear=jclrKnUbxSsmkPo01YGJFc4O9l3kt79RUdjpUT9mB3E=; NSC_pmvj2-NzNfssjmm-wt=9fea903a0000; pxsq=19
{"username":"username","rememberMe":false,"password":"mypassword","data":null}
{} 用于 JSON。这是我目前的代码:
//Get the variables
string url = "http://olui.fs.ml.com/Login/Login.aspx";
string userName = loginUN;
string userPassword = loginPW;
//Connection Parameters
string method = "POST";
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create("https://olui2.fs.ml.com/ClientFederation/LoginValidateUser.asmx/ValidatePassword");
webReq.Connection = "keep-alive";
webReq.ContentLength = 76;
webReq.UserAgent = " Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.103 Safari/537.36";
webReq.ContentType = "application/json; charset=UTF-8";
webReq.Accept = "*/*";
webReq.Referer = " https://olui2.fs.ml.com/login/ConfirmIdentity.aspx";
我不确定如何设置登录时需要使用的 cookie。其次,在我的 WebRequest
中找不到请求的一些部分,我。 e. Accept-Language、Cache-Control、X-Request 和南方的所有部分。
我不确定的另一件大事是用户名和密码的JSON。
您在一个问题中有多个挑战。也许最好将你的一组问题分成多个问题。
无论如何,我将重点关注您首先提到的 cookie 挑战。 HttpWebRequest
组件有一个 CookieContainer
属性。您需要创建 cookie 容器的实例并将其附加到特定的 属性。示例:
HttpWebRequest webReq = ...
webReq.CookieContainer = new CookieContainer();
webReq.CookieContainer.Add(new Cookie("name", "value", "/", yourDomain));
// etc.
这是一个不错的博客,可能会提供更多帮助:http://blogs.msdn.com/b/adarshk/archive/2004/08/24/219714.aspx