使用苏飞httphelper开发自动更新发布文章程序
作者:互联网
最近新上线了一个网站,专门收集网上签到赚钱,有奖活动等等的网站 我就要集分宝 http://www.591jfb.com。新建立 了一个栏目“每日更新”,这样就需要每天都登录到网站后台去发布文章,感觉有些繁琐,于是就想找点省劲的办法,于是便有了此文。
搜索下载了苏飞提供的httphelper,比着例子写了一下程序,结果返回的html总是错误页,于是又翻sufeinet论坛上面的帖子,搜索到有人用苏飞开发助手测试远程发布,于是也下载下来测试了一下,结果成功了,对照苏飞开发助手生成的代码和我写的代码的差别,最终发现问题出现在cookie上面。直接写result.cookie赋值的cookie值有一些path=/ 类似的字符串。
最终使用代码如下:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Utility; namespace PostArticle2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { HttpHelper http = new HttpHelper(); HttpItem item = null; HttpResult result = null; item = new HttpItem() { URL = "http://php.sxg.com/zb_system/cmd.php?act=verify", Referer = "http://php.sxg.com/zb_system/login.php", Method = "post",//URL 可选项 默认为Get ContentType = "application/x-www-form-urlencoded", Postdata = "btnPost=%E7%99%BB%E5%BD%95&username=username&password=pwd&savedate=0&dishtml5=0", }; result = http.GetHtml(item); string cookie = string.Empty; foreach (CookieItem s in HttpCookieHelper.GetCookieList(result.Cookie)) { cookie += HttpCookieHelper.CookieFormat(s.Key, s.Value); } item = new HttpItem() { URL = "http://php.sxg.com/zb_system/cmd.php?act=ArticlePst", Referer = "http://php.sxg.com/zb_system/admin/edit.php?act=ArticleEdt", Cookie = cookie, Method = "post", Postdata = "ID=0&Type=0&Title=1720sxg&Content=%3Cp%3Esxgsxg%3C%2Fp%3E&meta_keywords=&meta_description=&Alias=&Tag=&Intro=&CateID=1&Status=0&Template=single&AuthorID=1&PostTime=2015-01-13+11%3A37%3A01&IsTop=0&IsLock=0", Allowautoredirect = true, ContentType = "application/x-www-form-urlencoded", Host = "php.sxg.com", ResultType = ResultType.String }; http.GetHtml(item); } } }
标签:http,httphelper,System,苏飞,cookie,自动更新,using,php,com 来源: https://blog.51cto.com/anlaoliu/2873851