当前位置:编程学习 > C#/ASP.NET >>

HttpWebRequest post传参


我要获取它下一页的链接.这里它用的表单提交,所以这里获取不到.

他的下一页的参数在这里,就是图中红线圈起来的.

这是我的代码,画红线处是需要获取它图2中的参数的地方.请问各位大侠,在这里该如何获取. --------------------编程问答--------------------
是当前页的参数么 

1.如果html源码有 你就读取html
2.如果没有 就自子找规则
--------------------编程问答--------------------
是当前页面的源码并且也有.现在我是想问,怎么来传图片中的post里的参数. --------------------编程问答-------------------- 简单来说就是我要用我的方法给页面的post传值. --------------------编程问答-------------------- 获取httpwebrequest的stream,然后write需要post的数据即可。 --------------------编程问答-------------------- 建议你用微软进一步封装好的 WebClient.UploadData --------------------编程问答-------------------- public static HttpWebResponse CreatePostHttpResponse(string url, IDictionary<string, string> parameters, int? timeout, string userAgent, Encoding requestEncoding, CookieCollection cookies, bool allowAutoRedirect = true)
        {
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException("url");
            }
            if (requestEncoding == null)
            {
                throw new ArgumentNullException("requestEncoding");
            }
            HttpWebRequest request = null;
            //如果是发送HTTPS请求  
            if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
            {
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                request = WebRequest.Create(url) as HttpWebRequest;
                request.ProtocolVersion = HttpVersion.Version10;
            }
            else
            {
                request = WebRequest.Create(url) as HttpWebRequest;
            }
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.AllowAutoRedirect = allowAutoRedirect;

            if (!string.IsNullOrEmpty(userAgent))
            {
                request.UserAgent = userAgent;
            }
            else
            {
                request.UserAgent = DefaultUserAgent;
            }

            if (timeout.HasValue)
            {
                request.Timeout = timeout.Value;
            }
            if (cookies != null)
            {
                request.CookieContainer = new CookieContainer();
                request.CookieContainer.Add(cookies);
            }
            //如果需要POST数据  
            if (!(parameters == null || parameters.Count == 0))
            {
                StringBuilder buffer = new StringBuilder();
                int i = 0;
                foreach (string key in parameters.Keys)
                {
                    if (i > 0)
                    {
                        buffer.Append("&");
                        //buffer.AppendFormat("&{0}={1}", key, parameters[key]);
                    }
                    //else
                    string val = parameters[key];
                    val = val.Trim();
                    if (val.IndexOf("|") != -1)
                    {
                        string[] items = val.Split('|');
                        int j = 0;
                        foreach (string item in items)
                        {
                            if (j > 0)
                            {
                                buffer.Append("&");
                            }
                            buffer.AppendFormat("{0}={1}", key, item);
                            ++j;
                        }
                    }
                    else
                    {
                        buffer.AppendFormat("{0}={1}", key, val);
                    }
                    i++;
                }
                byte[] data = requestEncoding.GetBytes(buffer.ToString());
                using (Stream stream = request.GetRequestStream())
                {
                    stream.Write(data, 0, data.Length);
                }
            }
            else
            {
                request.ContentLength = 0;
            }
            return request.GetResponse() as HttpWebResponse;
        }

        private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
        {
            return true; //总是接受  
        }
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,