【问题标题】:Too many automatic redirections were attempted (even CookieContainer fail)尝试了太多自动重定向(甚至 CookieContainer 失败)
【发布时间】:2015-03-23 11:59:00
【问题描述】:

c#代码:

ASCIIEncoding encoding = new ASCIIEncoding();
CookieContainer cook = new CookieContainer();
byte[] data = encoding.GetBytes(postData);
HttpWebRequest myRequest =(HttpWebRequest)WebRequest.Create("http://website.com/index.php");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
//myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
//myRequest.AllowAutoRedirect = false;
myRequest.CookieContainer = new CookieContainer();
WebResponse response = myRequest.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
newStream = response.GetResponseStream();
StreamReader reader = new StreamReader(newStream);
Console.WriteLine(reader.ReadToEnd());

index.php

$num= $_POST["num"]; 
echo $num;

上面的代码以前对我有用,但突然失败了。我尝试了一切 添加CookieContainer(),将Redirection设置为false,使用其他代码进行httprequest。

如果我将AllowAutoRedirect 设置为 false,结果将是:


302 找到

找到 文档已移至此处


但是当我在其他网络托管服务器上尝试这个时,它可以工作。所以我在想它在我的 WHM/cPanel 上?此外,我已经将我的 IP 列入白名单。已经检查 .htaccess 和我的 cpanelb(redirection) 中的选项。

那么有什么想法可能导致这种情况吗?

注意:我已经禁用了云耀斑保护

【问题讨论】:

  • 有人吗?这仅发生在一周前。 CloudFlare 是否与此有关?因为我在所有域中都安装了插件

标签: c# php


【解决方案1】:

已经找到解决方案。就在他们更新了我的 WHM 并且在 ModSecurity 工具中添加了一些我不知道的规则时。我只是禁用它,一切都恢复正常:)

【讨论】:

    猜你喜欢
    • 2017-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-05
    相关资源
    最近更新 更多