標籤:
最近新上線了一個網站,專門收集網上籤到賺錢,有獎活動等等的網站 我就要集分寶 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); } }}
使用蘇飛httphelper開發自動更新發布文章程式