HttpWebRequest SSL授权表单

时间:2010-01-10 01:27:34

标签: ssl https httpwebrequest

我以前从未尝试过,但现在我真的需要通过Sprint的网站(www.sprint.com)获得授权。

你能帮助我了解这实际上是如何运作的吗?

我试图这样做,但显然我错过了一些东西。关于cookies的事情 或ssl或其他东西,我不知道。

  HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(
                                                "https://sso.sprintpcs.com/sso/Login.do");
  CookieContainer cookieContainer = new CookieContainer();
  webRequest.CookieContainer = cookieContainer;
  webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0;
                          chromeframe; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; 
                          .NET CLR 3.0.30729; Tablet PC 2.0; .NET4.0C; .NET4.0E)";
  webRequest.Accept = "image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, 
                       image/pjpeg, application/x-ms-xbap, application/x-shockwave-flash,
                       application/vnd.ms-excel, application/msword, */*";

  webRequest.Method = "POST";
  webRequest.Host = "manage.sprintpcs.com";

  string strUserId = "kindauser";
  string strPass = "kindapass";

  ASCIIEncoding encoding = new ASCIIEncoding();
  string postData = "userid=" + strUserId + "&password=" 
                    + strPass + "&userExperince=USC allowlogin=false";

  byte[] data = encoding.GetBytes(postData);
  Stream requestStream = webRequest.GetRequestStream();
  requestStream.Write(data,0,data.Length);

  HttpWebResponse myHttpWebResponse = (HttpWebResponse)webRequest.GetResponse();

1 个答案:

答案 0 :(得分:1)

我会执行以下操作 - 这适用于您希望与网站进行互动的所有情况。

1)获取firefox以及firebug扩展。 2)清除firefox内容和cookie缓存 3)使用firefox来完成场景 - 登录网站,例如。 4)此时,firebug会向您显示与cookie标头等一起发送的请求的确切顺序。

5)现在尝试使用代码复制它。