C#模拟登录中国联通获取用户通话详单

我写一个根据手机号码和服务密码自动登录中国联通官网 然后获取通话详单json的类,第一步模拟登录返回的数据没有问题 但是第二步获取通话详单的时候总是报500错误 有人知道解决方法吗?
public static string GetCalldetails(string userName, string password)
{
string content="";
CookieContainer cookie = new CookieContainer();
string postUrl = "https://uac.10010.com/portal/Service/MallLogin?callback=jQuery17202691898950318097_1403425938090&redirectURL=http://www.10010.com&userName="+userName+"&password="+password+"&pwdType=01&productType=01&redirectType=01&rememberMe=1";

          HttpWebRequest httpRequset = (HttpWebRequest)WebRequest.Create(postUrl);
          httpRequset.CookieContainer = cookie;//设置cookie
          httpRequset.Method = "GET";
          httpRequset.ContentType = "text/html;charset=UTF-8";

          HttpWebResponse httpresponse = (HttpWebResponse)httpRequset.GetResponse();
          Stream myResponseStream = httpresponse.GetResponseStream();
          StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
          string retString = myStreamReader.ReadToEnd();
          myStreamReader.Close();
          myResponseStream.Close();
          if (Convert.ToInt32(httpresponse.StatusCode) == 200)
          {
              if (retString.Contains("resultCode:\"0000\""))
              {
                  string billurl = "http://iservice.10010.com/e3/static/query/callDetail?_=1450840337718&menuid=000100030001";
                  string strdata = "pageNo=1&pageSize=100&beginDate=2015-12-01&endDate=2015-12-23";
                  byte[] byteArray = Encoding.UTF8.GetBytes(strdata); 
                  //string billurl = "http://iservice.10010.com/e3/static/check/checklogin/?_=1450857473494";
                 // HttpWebRequest Requset = (HttpWebRequest)WebRequest.Create(billurl);
                  HttpWebRequest Requset = (HttpWebRequest)WebRequest.Create(billurl);
                  Requset.Method = "POST";
                  Requset.CookieContainer = cookie;
                  Requset.ContentType = "application/x-www-form-urlencoded";
                  Stream stream = Requset.GetRequestStream();
                  using (StreamWriter myStreamWriter = new StreamWriter(stream, Encoding.GetEncoding("UTF-8")))
                  {
                      myStreamWriter.Write(byteArray);
                  }

                  HttpWebResponse response = (HttpWebResponse)Requset.GetResponse();
                  //if (Convert.ToInt32(response.StatusCode) == 200)
                  //{
                  using (Stream responsestream = response.GetResponseStream())
                  {

                      using (StreamReader sr = new StreamReader(responsestream, Encoding.GetEncoding("utf-8")))
                      {
                          content = sr.ReadToEnd();
                          //return content;
                      }
                  }
                  return content;
              }
              else
              {

                  return "登录失败:" + retString + "";
              }
          }
          else
          {
              int num = Convert.ToInt32(httpresponse.StatusCode);
              return "数据传输失败:" + num+"";
          }
         }

1个回答

500错误是服务器造成的,用fiddler调试下,看你的提交和浏览器的有什么不同以及服务器返回什么

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐