(1)使用httpRequest方式,执行结束也提示日志写成功,但是实际并没有写日志;(2)WebBrose方式,能写日志,但是总是提示脚本错误是否调试,选择"否",
是可以成功写日志,但是那个脚本错误一直无法去掉
//httpRequest方式登陆,写日志using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Net;namespace xiaoneiwangblog{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){//校内网用户名和密码username.Text = "[email protected]";password.Text = "rfv123";}//在校内网写日志private void button1_Click(object sender, EventArgs e){string user = username.Text; //校内网用户名string pwd = password.Text; //校内网密码 string blogtitle = title.Text; //日志标题string blogbody = body.Text; //日志正文//登陆校内网CookieContainer cookies = login(user, pwd);HttpWebRequest sendreq = (HttpWebRequest)WebRequest.Create("http://blog.xiaonei.com/NewEntry.do");byte[] message = Encoding.UTF8.GetBytes("title=" + blogtitle + "&body=" + blogbody + "&categoryid=0&blogControl=99&passwordProtedted=0");sendreq.ContentType = "application/x-www-form-urlencoded";sendreq.Method = "POST";sendreq.ContentLength = message.Length;sendreq.CookieContainer = cookies;sendreq.GetRequestStream().Write(message, 0, message.Length);sendreq.GetRequestStream().Close();sendreq.GetResponse();MessageBox.Show("恭喜您,您的日志已经发表成功,请查看!~");}//登陆校内网public CookieContainer login(string username, string password){CookieContainer cookies = new CookieContainer();HttpWebRequest logreq = (HttpWebRequest)WebRequest.Create("http://login.xiaonei.com/Login.do");logreq.CookieContainer = cookies;byte[] postdata = Encoding.UTF8.GetBytes("email=" + username + "&password=" + password);logreq.Method = "POST";logreq.ContentLength = postdata.Length;logreq.ContentType = "application/x-www-form-urlencoded";logreq.GetRequestStream().Write(postdata, 0, postdata.Length);logreq.GetRequestStream().Close();logreq.GetResponse();return cookies;}//清空已填写的用户名、密码以、日志标题和正文private void button2_Click(object sender, EventArgs e){username.Text = null;password.Text = null;title.Text = null;body.Text = null;} }}
是可以成功写日志,但是那个脚本错误一直无法去掉
//httpRequest方式登陆,写日志using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Net;namespace xiaoneiwangblog{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){//校内网用户名和密码username.Text = "[email protected]";password.Text = "rfv123";}//在校内网写日志private void button1_Click(object sender, EventArgs e){string user = username.Text; //校内网用户名string pwd = password.Text; //校内网密码 string blogtitle = title.Text; //日志标题string blogbody = body.Text; //日志正文//登陆校内网CookieContainer cookies = login(user, pwd);HttpWebRequest sendreq = (HttpWebRequest)WebRequest.Create("http://blog.xiaonei.com/NewEntry.do");byte[] message = Encoding.UTF8.GetBytes("title=" + blogtitle + "&body=" + blogbody + "&categoryid=0&blogControl=99&passwordProtedted=0");sendreq.ContentType = "application/x-www-form-urlencoded";sendreq.Method = "POST";sendreq.ContentLength = message.Length;sendreq.CookieContainer = cookies;sendreq.GetRequestStream().Write(message, 0, message.Length);sendreq.GetRequestStream().Close();sendreq.GetResponse();MessageBox.Show("恭喜您,您的日志已经发表成功,请查看!~");}//登陆校内网public CookieContainer login(string username, string password){CookieContainer cookies = new CookieContainer();HttpWebRequest logreq = (HttpWebRequest)WebRequest.Create("http://login.xiaonei.com/Login.do");logreq.CookieContainer = cookies;byte[] postdata = Encoding.UTF8.GetBytes("email=" + username + "&password=" + password);logreq.Method = "POST";logreq.ContentLength = postdata.Length;logreq.ContentType = "application/x-www-form-urlencoded";logreq.GetRequestStream().Write(postdata, 0, postdata.Length);logreq.GetRequestStream().Close();logreq.GetResponse();return cookies;}//清空已填写的用户名、密码以、日志标题和正文private void button2_Click(object sender, EventArgs e){username.Text = null;password.Text = null;title.Text = null;body.Text = null;} }}
解决方案 »
- datagridview 显示和添加繁体数据
- c# Datetime保存数据时如何保存毫秒?读取GB2312数据如何读取?
- datagraview 读文本文件的内容的问题
- dataGridview中单元格的值只允许输入数字???
- 频繁写入数据库是连接的处理问题
- 用C#做一个资源管理器
- 怎么调用oracle的存储过程呀
- 如何获取一个字符串在另一个字符串中出现的次数!
- 请教:我在一个Panel上放了几个Button,我想在点击Button时,Panel能感知到。(内详)
- 第一帖-点击按钮 生成几个不同控件并能对这些控件实现操作
- [求助]如何实现论坛刷帖(增加点击量)功能?
- 如何逐行读取多行文本框中的内容
try //发帖模块{//跳转到发帖页面Thread.Sleep(3000); //等待3秒 webBrowser1.Navigate("http://blog.xiaonei.com/NewEntry.do");Thread.Sleep(3000); //等待3秒 HtmlElement tbTitile = webBrowser1.Document.All["title"];HtmlElement tbBody = webBrowser1.Document.All["body"];//HtmlElement btnSubmit2 = webBrowser1.Document.All["editorFormBtn"]; //返回nullHtmlElement btnSubmit2 = webBrowser1.Document.GetElementById("editorFormBtn");tbTitile.SetAttribute("value", "testTitle123"); //返回nulltbBody.SetAttribute("value", "testBody456"); //返回nullbtnSubmit2.InvokeMember("click");Thread.Sleep(2000); //等待2秒 webBrowser1.Navigate("http://blog.xiaonei.com/NewEntry.do");}catch (Exception ex){//MessageBox.Show(ex.ToString());}}
}}
字符:1
代码:0
错误:'window.tinyMCE.activeEditor'为空或不是对象RUL: http://blog.renren.com.blog/0/addBlog