整半夜了,还是返回503,无语了,哪位大神给个例子或指点下小弟。。

解决方案 »

  1.   

    就是一个模拟POST表单数据的过程
      

  2.   

    这是用微波控制电脑关机的程序,里面有怎么样访问新浪的微薄的方法,你换下地址估计就可以了//运行
    private void button1_Click(object sender, EventArgs e) 
            {
                username =this.userid.Text;
                password = this.pass.Text; //这里输入你自己微博登录的的密码
                this.textBox1.Text =  getFriends();
                this.timer1.Enabled = true;
            }
            private string getFriends()
            {
                try
                {
                    string s = "";
                    //string cursor = Convert.ToString(previous_cursor);
                    //string url = " http://api.t.sina.com.cn/statuses/friends.xml?source=" + "2031619991" + "&cursor=" + cursor;
                    string url = "http://api.t.sina.com.cn/statuses/user_timeline.xml?source=2031619991&user_id=" + username + "&count=1";
                    //string url = "http://api.t.sina.com.cn/statuses/repost_timeline.xml?source=2031619991&user_id=1181030493&count=1";                //注意这里的格式哦,为 "username:password"                System.Net.WebRequest webRequest = System.Net.WebRequest.Create(url);
                    System.Net.HttpWebRequest myReq = webRequest as System.Net.HttpWebRequest;                //身份验证
                    string usernamePassword = username + ":" + password;
                    CredentialCache mycache = new CredentialCache();
                    mycache.Add(new Uri(url), "Basic", new NetworkCredential(username, password));
                    myReq.Credentials = mycache;
                    myReq.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword)));                WebResponse wr = myReq.GetResponse();
                    Stream receiveStream = wr.GetResponseStream();
                    StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
                    string content = reader.ReadToEnd();
                    XmlDocument xmlDoc = new XmlDocument();                xmlDoc.LoadXml(content);
                    // xmlDoc.Load("data1.xml");                XmlNodeList nodeList = xmlDoc.SelectSingleNode("statuses").ChildNodes;//获取根节点的所有子节点
                    //XmlNodeList nodeList=
                    for (int k = 0; k < nodeList.Count; k++)
                    {
                        XmlElement xe = (XmlElement)nodeList.Item(k);
                        if (xe.Name == "status")
                        {
                            s = xe.SelectSingleNode("text").InnerText;
                            weiboid = xe.SelectSingleNode("id").InnerText;
                            weibotime = xe.SelectSingleNode("created_at").InnerText;
                        }
                    }
                    //string s = nodeList.Item;
                    // next_cursor = Convert.ToInt16(nodeList.Item(nodeList.Count - 2).InnerText);
                    // previous_cursor = Convert.ToInt16(nodeList.Item(nodeList.Count-1).InnerText);                xmlDoc.Save("new.xml");
                    return s;
                }catch(Exception ex)
                {
                    return "error:"+ex;
                }
            }
          
            private void timer1_Tick(object sender, EventArgs e)
            {
                string cmd = getFriends();
                if (cmd == "")
                {
                    this.label3.Text = "请登录";
                    return;
                }
                this.textBox1.Text = cmd;
                if (cmd == "关机")
                {
                    
                    if (getcmd() != weiboid)
                    {
                        addcmd();
                        this.label3.Text = "关机";
                        shutdown();
                    }
                    else
                    {
                        this.label3.Text = "";
                    }            }
                else
                {
                    this.label3.Text = "";
                }
            }        private void addcmd()
            {
                XmlDocument doc = new XmlDocument();
                doc.Load("cmd.xml");
                XmlNode root = doc.DocumentElement;            //Create a new node.
                XmlElement elem1 = doc.CreateElement("weiboid");
                elem1.InnerText = weiboid;
                XmlElement elem = doc.CreateElement("weibotime");
                elem.InnerText = weibotime+weiboid;
                            //Add the node to the document.
                root.AppendChild(elem);
                root.AppendChild(elem1);
                doc.Save("cmd.xml");
            }
            private string  getcmd()
            {
                string s = "";
                XmlDocument doc = new XmlDocument();
                doc.Load("cmd.xml");            XmlNodeList nodeList = doc.SelectSingleNode("statuses").ChildNodes;//获取根节点的所有子节点
                //XmlNodeList nodeList=
                for (int k = nodeList.Count-1; k >0; k--)
                {
                    XmlElement xe = (XmlElement)nodeList.Item(k);
                    if (xe.Name == "weiboid")
                    {
                        //s = xe.SelectSingleNode("text").InnerText;
                        s = xe.InnerText;
                        break;
                    }
                }            return s;
            }
            void shutdown()
            {
                //设定关机
                AdjustToken();
                for (int i = 10; i > 0; i--)
                {
                    this.label3.Text = i.ToString() + " 秒后执行关机!!";
                    System.Threading.Thread.Sleep(1000);
                    Refresh();
                    
                }
                    ExitWindowsEx(ExitWindows.EWX_POWEROFF, 0);        }        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
            {
                System.Diagnostics.Process.Start("http://dearcoder.cn/DownloadClass.html");
            }
      

  3.   

    哥们,百度使用的是https加密协议,请求类型为POST,你这种的程序我也有,就是改了很多次在百度上还是不行。
      

  4.   

    用HTTP抓包工具抓一下你的代码的实际发送包和百度的包有什么不同就查出来了。
      

  5.   

    百度登录用的是https协议,数据是看不到的