烦恼! POST返回一个302找到对象的HttpWebRequest移动错误 [英] vexed! POST returns a 302 found object moved error in HttpWebRequest

查看:393
本文介绍了烦恼! POST返回一个302找到对象的HttpWebRequest移动错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人请帮助! - 已疲于应付这个问题的糟糕

Someone please help - been struggling with this lousy problem!

我在做什么 - 我有一个ASPX页面从我发起GET再张贴到 HTTPS 页,以登录到它。我花了相当多的时间使用招(协议分析仪)我GET和POST建设比较浏览器GET / POST和我的要求都是精品。

What I'm doing - I have an ASPX page from which I originate a GET and then a POST to a HTTPS page with a view to login to it. I have spent quite a bit of time comparing my GET and POST construction to a browser GET/POST using fiddler (protocol analyzer) and my requests are fine.

然而,当我尝试通过浏览器登录,一切工作正常,并记录。当我跑我的网页,我可以看到正确的GET和POST,但我得到一个302找到对象移到错误

However, when I try login through the browser, everything works fine and it logs in. When I run my page, I can see the correct GET and POST, but I get a 302 found 'object moved error'

原本我以为这是一个cookie的问题,但多次实验后,我pretty肯定这无关与饼干。我有残疾的cookies和JavaScript的浏览器,并试图和页面,而无需任何正常工作。然后我模拟的准确GET / POST。

Originally I thought this was a cookie issue, but after much experimentation I'm pretty sure this has nothing to do with cookies. I have disabled cookies AND javascript on the browser and tried, and the pages work fine without either. I then simulated the exact GET/POST.

这是我的情况:


  1. 我的GET和浏览器中出现完全相同

  2. 从网站上的200 OK响应是一致,除了它们具有略微不同长度的3 VIEWSTATE变量相同(为什么?为什么不同,即使GET是一样的吗?)

  3. 我的文章和浏览器POST正是除3视图状态变量相同(我正确填写其从GET)

  4. 然而,浏览器登录,而我得到一个302发现/对象移动errror。

一对夫妇的其他东西 -

A couple of other things -

一)我复制从最近浏览帖子的帖子反应,取代了我的POST PARAMS使用这个浏览器POST和这让我正确的反应!这表明,结果
  - 我的头也蛮好结果
  - 我的编码设置/环境等都是精品结果
  - 这是在ViewState值,只能是因为浏览器首先把它交给我腥(没有在我的解析GET VIEWSTATE变量,并在后期使用它没有损坏,它是完美的罚款)

a) I copied the POST response from a recent browser POST and replaced my POST params with this browser POST and that got me the right response! This indicates that
- my headers are just fine
- my coding setup / environment etc. are fine
- something fishy in the VIEWSTATE values, which can only be because the browser sent it to me in the first place (there is no corruption in my parsing the GET VIEWSTATE variables and using it in POST, it's perfectly fine)

更新我也试图WebClient的只是为了检查 - 没有任何区别,同样的302。
更新对象移动主要指它说发生了严重的错误等等等等一个错误页 - 在POST在服务器上造成的错误,和良好的POST之间的唯一区别(浏览器)和我的职务是视图状态变量。

update I have also tried WebClient just to check - no difference, same 302. update The object moved basically points to a error page which says 'a serious error occurred blah blah' - the POST is causing a error at the server, and the ONLY difference between the good POST (of the browser) and my POST are the Viewstate variables.

所以 - 我到底做错了什么?为什么这个残酷的世界折磨着我?!

So - WHAT AM I DOING WRONG? Why is this cruel world tormenting me?!!

(PS - 在浏览器中序列另外一个区别,不知道如何事项)

(PS - one other difference in the browser sequence, not sure how it matters)


浏览器:结果
CONNECT结果
GET结果
GET(一个图标,它返回一个错误)结果
CONNECT结果
POST(成功)结果
我:结果
CONNECT结果
GET结果
POST(燃烧的失败,302 - 页面移动)结果

对于那些谁照顾,我的帖子标题建设code

and for those who care, my POST header construction code

    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(URL);
    myRequest.UserAgent = chromeUserAgent;

    //myRequest.CookieContainer = cCookies;
    myRequest.ContentType = "application/x-www-form-urlencoded";
    myRequest.Accept = chromeAccept;
    myRequest.Referer = url;
    myRequest.AllowAutoRedirect = false;
    myRequest.Host = "thesitethatskillingme.com";
    myRequest.Headers.Add("Origin", "https://thesitethatskillingme.com");
    myRequest.Headers.Add("Accept-Encoding", chromeAcceptEncoding);
    myRequest.Headers.Add("Accept-Language", chromeAcceptLanguage);
    myRequest.Headers.Add("Accept-Charset", chromeAcceptCharset);
    myRequest.Headers.Add("Cache-Control", "max-age=0");
    myRequest.ServicePoint.Expect100Continue = false;
    myRequest.Method = "POST";
    myRequest.KeepAlive = true;

    ASCIIEncoding ascii = new ASCIIEncoding();
    byte[] bData = ascii.GetBytes(data);

    myRequest.ContentLength = bData.Length;

    using (Stream oStream = myRequest.GetRequestStream())
        oStream.Write(bData, 0, bData.Length);

...然后读取流等没有饼干。

...and then read stream etc. no cookies.

推荐答案

我终于想通了 - 希望别人谁在同样的问题的机会不必再经历这一点。这可能是大多数HTTP大师和人们熟悉的WWW的发展绝不会打它,但一个新手相当不错可以。

I finally figured it out - and hopefully someone else who chances upon the same problem does not have to go through this again. It's possible that most HTTP gurus and people familiar with WWW development would never hit it, but a newbie quite well could.

那么究竟是什么问题呢?我已经缩小的问题VIEWSTATE我一直怀疑(见上面我的帖子...)。事实证明,我不得不这样做是为了Server.UrlEn code解析VIEWSTATE值将它们放到POST面前 - 这是它。我花了一整天去了。

So what was the problem? I had narrowed down the problem to VIEWSTATE which I always suspected (see my post above...). It turns out that all I had to do was to Server.UrlEncode the parsed VIEWSTATE values before putting them onto POST - that's it. It took me all day to get to that.

所以,作为一个学习等新人

SO, as a learning to other newcomers


  • 如果你想通过code张贴到一个页面,所需要的,那么首先Server.UrlEn code将其创建参数之前发送它,你从GET解析VIEWSTATE变量 - 例如为

  • If you are trying to POST to a page through code and need to send it VIEWSTATE variables that you parsed from GET, then first Server.UrlEncode it before creating the parameters - for e.g.

因为我从来没有,曾经与HttpWebRequest的程序等等,我开始通过消除饼干,JavaScript的,建设GET,POST建设一个接一个使用招(伟大的分析工具,免费的),然后终于缩小我的问题没有使用BeyondCompare字节的比较,那就是当我赶上了VIEWSTATE变量修改。

because I have never, ever programmed with HttpWebRequest etc., I started by narrowing down my problem by eliminating cookies, javascript, GET construction, POST construction one-by-one using fiddler (great analyzer tool, free) and then finally did byte-comparison using BeyondCompare, and that's when I caught the VIEWSTATE variable modifications.

我学到了URL编码一个教训,希望你不会有!

I learnt a lesson on URL encoding, and hopefully you won't have to!

这篇关于烦恼! POST返回一个302找到对象的HttpWebRequest移动错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆