开发者

HttpPost onto the asp server(HTML form)

Using HttpURLConnection and doing post to the server I obtain the redirect page with the location header. Status code 302, so I must use this information to proceed to the redirect. (Everything seems to be ok here.. at least for me)

08-03 09:45:11.662: INFO/System.out(1664): <html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="http://website/mobile/(X(1)S(sf3dah5520rblujg4z2n0n55))/Login.aspx?ReturnUrl=%2fsyspower3%2fmobile%2fDefault.aspx&amp;AspxAutoDetectCookieSupport=1">here</a>.</h2>
</body></html>
08-03 09:45:11.662: INFO/System.out(1664): Status code - 302
08-03 09:45:11.672: INFO/System.out(1664): location : [http://website/mobile/(X(1)S(sf3dah5520rblujg4z2n0n55))/Login.aspx?ReturnUrl=%2fsyspower3%2fmobile%2fDefault.aspx&AspxAutoDetectCookieSupport=1]
08-03 09:45:11.672: INFO/System.out(1664): x-powered-by : [ASP.NET]
08-03 09:45:11.672: INFO/System.out(1664): content-type : [text/html; charset=utf-8]
08-03 09:45:11.672: INFO/Sys开发者_如何学Gotem.out(1664): content-length : [282]
08-03 09:45:11.672: INFO/System.out(1664): date : [Wed, 03 Aug 2011 09:45:00 GMT]
08-03 09:45:11.672: INFO/System.out(1664): server : [Microsoft-IIS/7.5]
08-03 09:45:11.672: INFO/System.out(1664): location found: http://website/mobile/(X(1)S(sf3dah5520rblujg4z2n0n55))/Login.aspx?ReturnUrl=%2fsyspower3%2fmobile%2fDefault.aspx&AspxAutoDetectCookieSupport=1

After this, if i use this link in the normal browser, i can go into the server without logon, so practically this link is the one i should use to make a post to and obtain the information that is inside the server after the logon. (And it actually does it if I use it in browser)

Problem: If i do the new POST to the server already with the new location, i get to the logon screen again. Should I be using cookies for the new request or what is my problem?


Yes, cookies should solve your problem. When you are working with browser you get Set-Cookie response header when you go to the site first time. Then when you continue the browser sends header Cookie with all cookies in it.

One of cookie contains HTTP session ID. For example java based servers use cookie jsessionid. This cookie is used by server to identify your session when you perform second, third etc request. If this field is absent server creates new session every time. The session is new, therefore is not authenticated, so you are redirected to login page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜