模拟登录开源众包平台
1、打开开发者工具,找到登录api
2、在Payload中查看到Post的数据格式
3、模拟登陆
HttpWebRequest request = HttpWebRequest.CreateHttp("https://zb.oschina.net/login/doLogin");
request.Method = "POST";
request.ContentType = "application/json;charset=UTF-8";
using (Stream request_stream = request.GetRequestStream())
{
byte[] body = Encoding.UTF8.GetBytes("{\"username\":\"*****\",\"password\":\"****\"}");
request_stream.Write(body, 0, body.Length);
}
HttpWebResponse httpresponse = (HttpWebResponse)request.GetResponse();
string response= "";
using (StreamReader reader = new StreamReader(httpresponse .GetResponseStream(), Encoding.UTF8))
{
response = reader.ReadToEnd();
return response;
}
4、获取网页源代码
HttpWebRequest request = HttpWebRequest.CreateHttp("https://zb.oschina.net/projects/list.html");
HttpWebResponse httpResponse = request.GetResponse() as HttpWebResponse;
using(StreamReader sr=new StreamReader(httpResponse.GetResponseStream(), Encoding.UTF8))
{
string responseText= sr.ReadToEnd();
return responseText;
}