c#做post提交,如何实现代理ip

一棵帅白菜 2015-04-29 03:25:34
现在是用c#做的post提交请求。信息做的随机生成。模拟真实用户。现在遇到一个问题是如何来做通过不同的ip提交呢。笨的办法是通过断开重新拨号猫,一方面是速度慢。另一方面是这种ip也是一个市的。c#如何实现代理IP呢。
...全文
630 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
橘子皮... 2019-06-01
  • 打赏
  • 举报
回复
引用 9 楼 失落的神庙 的回复:

 public static string doPost(string Url, byte[] postData, SinaCookie bCookie, String encodingFormat, String referer, string ProxyStr)
        {
                try
                {
                    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Url.ToString());
                    if (ProxyStr != ""&&ProxyStr != null)
                    {
                        //设置代理
                        WebProxy proxy = new WebProxy();
                        proxy.Address = new Uri(ProxyStr);
                        myRequest.UseDefaultCredentials = true;
                        myRequest.Proxy = proxy;
                    }
                    //myRequest.ServicePoint.Expect100Continue = false;
                    myRequest.CookieContainer = bCookie.mycookie;
                    myRequest.Method = "POST";
                    myRequest.Timeout = 30000;
                    myRequest.KeepAlive = true;//modify by yang
                    if (referer != "")
                        myRequest.Referer = referer;
                    myRequest.Headers["Cache-control"] = "no-cache";//.CachePolicy = .c "no-cache";//["Cache-control: no-cache"]
                    myRequest.Headers["Accept-Language"] = "zh-cn";
                    //myRequest.Headers["x-requested-with"] = "XMLHttpRequest";
                    myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Trident/4.0; GTB7.4; GTB7.1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2)";
                    myRequest.ContentType = "application/x-www-form-urlencoded";
                    myRequest.Accept = "*/*";
                    myRequest.ContentLength = postData.Length;

                    //setRequestHeader(requestHearder, myRequest);

                    Stream newStream = myRequest.GetRequestStream();
                    newStream.Write(postData, 0, postData.Length);
                    newStream.Close();
                    //if (waitTime != 0)
                    //    Thread.Sleep(waitTime);
                    HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
                    bCookie.upcookie(myResponse.Cookies);
                    StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.GetEncoding(encodingFormat));
                    string outdata = reader.ReadToEnd();
                    reader.Close();
                    if (!outdata.Contains("基础连接已经关闭: 连接被意外关闭") && !outdata.Contains("无法连接到远程服务器") && !outdata.Contains("基础连接已经关闭: 接收时发生错误。"))
                        return outdata;
                    else
                        return "基础连接已经关闭: 连接被意外关闭";

                }
                catch (Exception ex)
                {
                    if (!ex.Message.Contains("基础连接已经关闭: 连接被意外关闭") && !ex.Message.Contains("无法连接到远程服务器") && !ex.Message.Contains("基础连接已经关闭: 接收时发生错误。"))
                        return ex.Message;
                    else
                        return "基础连接已经关闭: 连接被意外关闭";
                }

        }
ProxyStr格式 http://192.168.1.1:80 大概是这样、
myRequest.UseDefaultCredentials = true 这句没什么用把
qq_41051959 2019-06-01
  • 打赏
  • 举报
回复
你那个sinacookie是加了什么引用吗
wenxingdage 2016-04-22
  • 打赏
  • 举报
回复
代理100是最新流行的很出色的一款免费的http代理ip软件,它拥有一个巨大的纯净代理IP库,每天为每位电脑用户免费提供各不相同的100个代理IP。 这些免费的代理ip与传统免费代理ip网站所提供代理ip质量大不相同,甚至远远超过了绝大部分商业代理ip平台。它的特点是:高质量、有效率99.99%、全面支持https协议、全部是高匿名级别,纯净绿色IP(非万人骑)、连接速度超快。 八大诱人特点: 1. IP来源:纯净度高、非互联网上被滥用的扫描代理ip; 2. 可用率:高达99%; 3. 稳定性:大多数稳定在30分钟-24小时,不排除极个别在几分钟; 4. 连接速度:超快,大部分在0.05秒这个响应速度级别; 5. 匿名级别:所有ip均为高匿级别; 6. https协议支持率:所有ip全部支持访问https网址; 7. post提交支持率:所有ip全部支持post提交方式; 8. 免费、免费、免费、免费、免费,还是免费,它竟然是免费的! 下载地址:http://www.ip181.com/daili100.html?D7D435FDEE17A346F249C56542A9970
失落的神庙 2016-03-09
  • 打赏
  • 举报
回复

 public static string doPost(string Url, byte[] postData, SinaCookie bCookie, String encodingFormat, String referer, string ProxyStr)
        {
                try
                {
                    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Url.ToString());
                    if (ProxyStr != ""&&ProxyStr != null)
                    {
                        //设置代理
                        WebProxy proxy = new WebProxy();
                        proxy.Address = new Uri(ProxyStr);
                        myRequest.UseDefaultCredentials = true;
                        myRequest.Proxy = proxy;
                    }
                    //myRequest.ServicePoint.Expect100Continue = false;
                    myRequest.CookieContainer = bCookie.mycookie;
                    myRequest.Method = "POST";
                    myRequest.Timeout = 30000;
                    myRequest.KeepAlive = true;//modify by yang
                    if (referer != "")
                        myRequest.Referer = referer;
                    myRequest.Headers["Cache-control"] = "no-cache";//.CachePolicy = .c "no-cache";//["Cache-control: no-cache"]
                    myRequest.Headers["Accept-Language"] = "zh-cn";
                    //myRequest.Headers["x-requested-with"] = "XMLHttpRequest";
                    myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Trident/4.0; GTB7.4; GTB7.1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2)";
                    myRequest.ContentType = "application/x-www-form-urlencoded";
                    myRequest.Accept = "*/*";
                    myRequest.ContentLength = postData.Length;

                    //setRequestHeader(requestHearder, myRequest);

                    Stream newStream = myRequest.GetRequestStream();
                    newStream.Write(postData, 0, postData.Length);
                    newStream.Close();
                    //if (waitTime != 0)
                    //    Thread.Sleep(waitTime);
                    HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
                    bCookie.upcookie(myResponse.Cookies);
                    StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.GetEncoding(encodingFormat));
                    string outdata = reader.ReadToEnd();
                    reader.Close();
                    if (!outdata.Contains("基础连接已经关闭: 连接被意外关闭") && !outdata.Contains("无法连接到远程服务器") && !outdata.Contains("基础连接已经关闭: 接收时发生错误。"))
                        return outdata;
                    else
                        return "基础连接已经关闭: 连接被意外关闭";

                }
                catch (Exception ex)
                {
                    if (!ex.Message.Contains("基础连接已经关闭: 连接被意外关闭") && !ex.Message.Contains("无法连接到远程服务器") && !ex.Message.Contains("基础连接已经关闭: 接收时发生错误。"))
                        return ex.Message;
                    else
                        return "基础连接已经关闭: 连接被意外关闭";
                }

        }
ProxyStr格式 http://192.168.1.1:80 大概是这样、
合光同尘 2016-03-09
  • 打赏
  • 举报
回复
可以的。这是可以做到的。
一棵帅白菜 2015-04-29
  • 打赏
  • 举报
回复
大神指点一下吧。。。
一棵帅白菜 2015-04-29
  • 打赏
  • 举报
回复
引用 5 楼 FoxDave 的回复:
内网可以换ip 外网不归你管,只能重新连接分配成新的ip吧
也是醉了。。。
Justin-Liu 2015-04-29
  • 打赏
  • 举报
回复
内网可以换ip 外网不归你管,只能重新连接分配成新的ip吧
一棵帅白菜 2015-04-29
  • 打赏
  • 举报
回复
引用 3 楼 FoxDave 的回复:
用笨方法吧,你这个看起来不像是个好东西啊
抱着学习的心态。其实就是c#如何实现代理IP。
Justin-Liu 2015-04-29
  • 打赏
  • 举报
回复
用笨方法吧,你这个看起来不像是个好东西啊
一棵帅白菜 2015-04-29
  • 打赏
  • 举报
回复
在线等大神。。。
一棵帅白菜 2015-04-29
  • 打赏
  • 举报
回复
post提交代码做完了,就是代理ip不会做了。

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧