可以通过登录验证,也可以获取到需要登录的页面内容,但发布不成功,返回的和直接访问页面的一样,请帮我看看哪里出了问题。string url = "http://t.sina.com.cn/mblog/publish.php";
HttpWebRequest requestScore = (HttpWebRequest)WebRequest.Create(url);
string postData = "content=" + content + "&pic=&styleid=1&retcode=";
//ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = Encoding.ASCII.GetBytes(postData); requestScore.Method = "Post";
requestScore.ContentType = "application/x-www-form-urlencoded";
requestScore.ContentLength = data.Length;
//requestScore.KeepAlive = true; //使用登陆的cookies通过接下来的验证
requestScore.CookieContainer = container;
Stream stream = requestScore.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
HttpWebResponse responseSorce = (HttpWebResponse)requestScore.GetResponse();
StreamReader reader = new StreamReader(responseSorce.GetResponseStream(), Encoding.UTF8);
try
{
return reader.ReadToEnd();
}
catch { return "\r\n"; }
HttpWebRequest requestScore = (HttpWebRequest)WebRequest.Create(url);
string postData = "content=" + content + "&pic=&styleid=1&retcode=";
//ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = Encoding.ASCII.GetBytes(postData); requestScore.Method = "Post";
requestScore.ContentType = "application/x-www-form-urlencoded";
requestScore.ContentLength = data.Length;
//requestScore.KeepAlive = true; //使用登陆的cookies通过接下来的验证
requestScore.CookieContainer = container;
Stream stream = requestScore.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
HttpWebResponse responseSorce = (HttpWebResponse)requestScore.GetResponse();
StreamReader reader = new StreamReader(responseSorce.GetResponseStream(), Encoding.UTF8);
try
{
return reader.ReadToEnd();
}
catch { return "\r\n"; }
System.Web.HttpUtility.UrlEncode(data);
UTF8或者GB2312这是最常用的编码