|
您好,通过C#HttpHelper类可以成功登录百度文库,并得到财富值,可是进行评分post时,总是显示操作超时,希望您在闲暇时可以帮忙解决一下。问题在最后一个post的地方。
var item = new HttpItem
{
Url = "https://passport.baidu.com/v2/?login&u=http://wenku.baidu.com/room?fr=room",//URL 必需项
Encoding = "",//编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
Method = "get",//URL 可选项 默认为Get
//Cookie = cookie//当前登录Cookie
Timeout = 6000
};
var result = _http.GetHtml(item);
var cookie = result.Cookie;
richTextBox1.Text += cookie + "\n\n";
item = new HttpItem
{
Url = "https://passport.baidu.com/v2/api/?getapi&tpl=pp&apiver=v3&class=login",//URL 必需项
Encoding = "",//编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
Method = "get",//URL 可选项 默认为Get
Cookie = cookie,//当前登录Cookie
Timeout = 6000
};
//得到HTML代码
result = _http.GetHtml(item);
var token = GetPattern("(?<=token\" : \")[^\"]+", result.Html);
richTextBox1.Text += token + "\n";
item = new HttpItem
{
Url = "https://passport.baidu.com/v2/api/?login", //URL 必需项
Encoding = "gbk", //编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
Method = "Post", //URL 可选项 默认为Get
ContentType = "application/x-www-form-urlencoded", //返回类型 可选项有默认值
//Post数据 使用URLEncode是为了解决中文用户名或者密码的问题 可选项GET时不需要写
Postdata = "staticpage=https%3A%2F%2Fpassport.baidu.com%2Fv3Jump.html&charset=utf-8&token="+token+"&tpl=pp&apiver=v3&codestring=&isPhone=false&safeflg=0&u=http%3A%2F%2Fwenku.baidu.com%2Froom%3Ffr%3Droom&username=你的账号&password=你的密码&verifycode=&callback=parent.bd__pcbs__kj4hu6",
Timeout = 6000,
Cookie = cookie,//当前登录Cookie
};
result = _http.GetHtml(item); //可以登录成功
cookie = result.Cookie;
richTextBox1.Text += cookie+ "\n\n";
item = new HttpItem
{
Url = "http://wenku.baidu.com/user/index",//URL 必需项
Encoding = "",//编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
Method = "get",//URL 可选项 默认为Get
Cookie = cookie,//当前登录Cookie
Timeout = 6000
};
//得到HTML代码
result = _http.GetHtml(item);
var wealth = GetPattern("(?<=wealth' : \")[^\"]+", result.Html);
richTextBox1.Text += wealth + "\n"; //可以成功得到财富值
item = new HttpItem
{
Url = "http://wenku.baidu.com/doc/submit/value", //URL 必需项
Encoding = "", //编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
Method = "Post", //URL 可选项 默认为Get
ContentType = "application/x-www-form-urlencoded", //返回类型 可选项有默认值
Postdata = "ct=20009&doc_id=e7e95bfb700abb68a982fbf6&value_score=4",
Timeout = 6000,
Referer = "http://wenku.baidu.com/view/e7e95bfb700abb68a982fbf6.html",
Allowautoredirect = true,
Cookie = cookie,//当前登录Cookie
};
result = _http.GetHtml(item);
richTextBox1.Text += result.Html+"\n\n\n"; //此处发生错误,总是显示操作超时,难道是cookie的问题吗?
|
|