douxiu6835 2015-03-11 08:39
浏览 140
已采纳

尝试了太多自动重定向(即使CookieContainer失败)

c# code:

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;

the above code work for me before but suddenly it fail. I tried everything adding CookieContainer(), setting Redirection to false, using other code for httprequest.

If I AllowAutoRedirect set to false the result would be:


302 Found

Found The document has moved here


But when i tried this to other web-hosting server it works. So i was thinking its on my WHM/cPanel? Also i have already white-listed my Ip. Already check .htaccess and the options in my cpanelb(redirection).

So any ideas what might cause this?

note: i have already disable'd cloud flare protection

  • 写回答

1条回答 默认 最新

  • dongwen3410 2015-03-23 03:59
    关注

    Already Found the solution. It was when they updated my WHM and some Rule was added in ModSecurity Tool that I was not aware off. I just disable that and everything was back to normal :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试