简体   繁体   中英

HTTP/1.1 302 Found - in Android after httpPost

after executing post method on the server i get this error: HTTP/1.1 302 Found, which as i know states that there is a redirect that follows. I am trying to fill in the logon form and post it to server, after doing so, i get this redirect.

PS The form submit method is postback.. maybe this is a key?

PPS After posting this:

__VIEWSTATE=&__EVENTTARGET=&__EVENTARGUMENT=&ctl00$tbUsername=qwerty&ctl00$tbPwd=qwerty&ctl00$chkRememberLogin=0&ctl00$cmdLogin=Login&ctl00$cmdForgetMe=Forget Me

I get this:

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="http://website/mobile/(X(1)S(lyslolvcdq13af45juum2vel))/Login.aspx?ReturnUrl=%2fsyspower3%2fmobile%2fdefault.aspx&amp;AspxAutoDetectCookieSupport=1">here</a>.</h2>
</body></html>

Plus the set of headers:

08-02 13:48:39.084: INFO/System.out(1853): ====Header=====
08-02 13:48:39.084: INFO/System.out(1853): Cache-Control
08-02 13:48:39.084: INFO/System.out(1853): private
08-02 13:48:39.084: INFO/System.out(1853): ====Header=====
08-02 13:48:39.084: INFO/System.out(1853): Content-Type
08-02 13:48:39.084: INFO/System.out(1853): text/html; charset=utf-8
08-02 13:48:39.093: INFO/System.out(1853): ====Header=====
08-02 13:48:39.093: INFO/System.out(1853): Expires
08-02 13:48:39.093: INFO/System.out(1853): Tue, 02 Aug 2011 13:48:33 GMT
08-02 13:48:39.093: INFO/System.out(1853): ====Header=====
08-02 13:48:39.093: INFO/System.out(1853): Server
08-02 13:48:39.093: INFO/System.out(1853): Microsoft-IIS/7.5
08-02 13:48:39.093: INFO/System.out(1853): ====Header=====
08-02 13:48:39.093: INFO/System.out(1853): Set-Cookie
08-02 13:48:39.093: INFO/System.out(1853): ASP.NET_SessionId=ebmsrf45wb3mcq45qrgrfe55; path=/; HttpOnly
08-02 13:48:39.093: INFO/System.out(1853): ====Header=====
08-02 13:48:39.104: INFO/System.out(1853): X-AspNet-Version
08-02 13:48:39.104: INFO/System.out(1853): 2.0.50727
08-02 13:48:39.104: INFO/System.out(1853): ====Header=====
08-02 13:48:39.104: INFO/System.out(1853): X-Powered-By
08-02 13:48:39.104: INFO/System.out(1853): ASP.NET
08-02 13:48:39.104: INFO/System.out(1853): ====Header=====
08-02 13:48:39.104: INFO/System.out(1853): Date
08-02 13:48:39.104: INFO/System.out(1853): Tue, 02 Aug 2011 13:48:33 GMT
08-02 13:48:39.104: INFO/System.out(1853): ====Header=====
08-02 13:48:39.104: INFO/System.out(1853): Content-Length
08-02 13:48:39.104: INFO/System.out(1853): 1272

EDITED : Now i can see the new location that I must proceed to. But here is a new problem, when i enter this new link into the browser, i get into the server(i pass login), but if I do a new request(POST) to server, then i am being thrown back to the login page...

PS Now i am using HttpURLConnection for the post method

That's not an error. That's just an informal message that there's a redirect. Only HTTP 4nn and 5nn responses are real errors. The redirect URL is available in the HTTP Location header. You, as being a web client, are obligated to send a new GET request on the URL as specified in the HTTP Location header.

String location = response.getLastHeader("Location").getValue();
// ...

Update : So, you got a HTTP 302 response without a Location header? What's the status code of the response itself?

int statusCode = response.getStatusLine().getStatusCode();

If this is 200 and the body contains a 302 message, then it's definitely a bug in the server side. The webserver should have returned a status code of 302 along with a Location header.


Update 2 : So, the status code is actually 200. That's a bug in the server side. If that website is not under your control and thus you cannot fix the server, then you need to report it to the admin/maintainer of the website. In the meanwhile, best what you could do is to extract the new location from the response body using some HTML parser and then send a new GET request on it. For example, using Jsoup :

String location = Jsoup.parse(responseHtml).select("h2 a").first().attr("href");
// ...

The code 302 is not considered an error. It is an instruction to the client that it should continue on to the location specified by the Location response header. The client should follow that directive and proceed to the indicated location.

Since this server isn't returning Location , it looks like you will have to parse the response body and follow the URL specified there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM