none
请教windfrom 程序 POST百度空间发表文字 RRS feed

  • 问题

  • //POST登录部分
                string postdata = "charset=UTF-8&codestring=&token=ab9a14d9bb810eb1fd1fccd38f5a82aa&isPhone=false&index=0&u=&"+
                    "safeflag=0&staticpage=http%3A%2F%2Fhi.baidu.com%2Fcom%2Fshow%2Fproxy%3Ffun%3Dcallback.login.submited&loginType=1&"+
                    "tpl=qing&username=zye7504&password=13054003440&verifycode=&mem_pass=on";
                byte[] byteArray = Encoding.Default.GetBytes(postdata);
                string url = "http://passport.baidu.com/v2/api/?login";

                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url));
                webRequest.Method = "POST";
                webRequest.ContentType = "application/x-www-form-urlencoded";
                webRequest.ContentLength = byteArray.Length;
                Stream newStream = webRequest.GetRequestStream();
                newStream.Write(byteArray, 0, byteArray.Length);
                newStream.Close();

                HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
                StreamReader php = new StreamReader(response.GetResponseStream(), Encoding.Default);
                string Message = php.ReadToEnd();

                textBox1.Text = Message;

                //POST发表文字部分
                postdata = "title=biaoti&content=<p>neirong<%2Fp>&private=0&imgnum=0&"+
                    "bdstoken=503b6e5c0684707d7d714dcb17b46b10&qbid=&refer=http:%2F%2Fhi.baidu.com%2Fhome&private1=0&qing_request_source=";
                byteArray = Encoding.Default.GetBytes(postdata);
                url = "http://hi.baidu.com/pub/submit/createtext";

                webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url));
                webRequest.Method = "POST";
                webRequest.ContentType = "application/x-www-form-urlencoded";
                webRequest.ContentLength = byteArray.Length;
                newStream = webRequest.GetRequestStream();
                newStream.Write(byteArray, 0, byteArray.Length);
                newStream.Close();

                response = (HttpWebResponse)webRequest.GetResponse();
                php = new StreamReader(response.GetResponseStream(), Encoding.Default);
                Message = php.ReadToEnd();

                textBox2.Text = Message;  //这里返回的好像是失败的东东。

    初学POST,查了一些资料,模仿着学习,没成功,请指点。

    2012年6月14日 23:33

答案

  • 建议下载一个http 抓包软件。

    自己在ie中完成一次操作,用抓包软件抓取所有交互信息。

    然后通过代码模拟即可。


    family as water

    2012年6月15日 3:13