English 中文(简体)
通过POST认证到ASP网站,并检索到html网页
原标题:authentication through POST to ASP site and getting back a html page

I have started writing an application that gets in a certain website and gets the information in the pages in a nicer cleaner way. My first problem is getting authenticated so I could download the pages. This is the site: https://www.ims.tau.ac.il/Tal/. It is in Hebrew but the top form goes (top to bottom): username, id number, password.

当我填写表格并点击SUBMIT但顿 I新闻社F12,见POST信息:

Request URL:https://www.ims.tau.ac.il/Tal/Login_Chk.aspx?rk=
Request Method:POST
Status Code:302 Found

Request Headersview parsed

POST /Tal/Login_Chk.aspx?rk= HTTP/1.1    
Host: www.ims.tau.ac.il    
Connection: keep-alive 
Content-Length: 82    
Cache-Control: max-age=0   
Origin: https://www.ims.tau.ac.il
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.120 Safari/535.2   
Content-Type: application/x-www-form-urlencoded    
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8    
Referer: https://www.ims.tau.ac.il/Tal/    
Accept-Encoding: gzip,deflate,sdch    
Accept-Language: en-US,en;q=0.8    
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3    
Cookie: ASP.NET_SessionId=2mi4i555jfibfb55wolrse55

Query String Parametersview URL encoded

rk:
Form Dataview URL encoded
user:MYUSERNAME
id_num:MYIDNUMBER
pass: MYREALPASSWORD
Enter.x:46
Enter.y:18
javatest:9
src:

Response Headersview parsed

HTTP/1.1 302 Found    
Date: Wed, 16 Nov 2011 21:25:46 GMT    
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET    
X-AspNet-Version: 2.0.50727    
Location: Sys/Main.aspx?id=021653167&sys=tal&rk=&dt=16/11/2011 11:25:46 PM    
Cache-Control: private    
Content-Type: text/html; charset=utf-8   
Content-Length: 207

我试图从我在论坛其他岗位上发现的法典中抽出,但我无法工作:

public class MyTauRobot implements Runnable {

    private static final String TAG = "MyTauActivity";

    String name;
    String id;
    String pass;
    String result;

        public MyTauRobot() {
        super();
    }

    public MyTauRobot(String name, String id, String pass) {
        super();
        this.name = name;
        this.id = id;
        this.pass = pass;
    }

    @Override
    public void run() {
        HttpClient postClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost("https://www.ims.tau.ac.il/Tal/Login_Chk.aspx?rk=");
        HttpResponse response;


        try {

            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("user", name));
            nameValuePairs.add(new BasicNameValuePair("id_num", id));
            nameValuePairs.add(new BasicNameValuePair("pass", pass));

            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            response = postClient.execute(httpPost);

            if(response.getStatusLine().getStatusCode() == 200) {
                HttpEntity entity = response.getEntity();

            }           

            Log.v(TAG,EntityUtils.toString(response.getEntity())); 

        } catch (Exception e) {
            Log.d(TAG, e.toString());
            Log.d(TAG, e.getCause().toString());
            }
        }
}

当我执政时,我就有一个例外。

org.apache.http.client.ClientProtocolException
11-19 22:42:48.758: D/MyTauActivity(726): org.apache.http.ProtocolException: Invalid redirect 
URI: Default.aspx?id=&rk=&src=&dt=20/11/2011 12:42:48 AM

UPDATE: I still get an exception but I ve found out that atlist it seems to be logging in right the exception comes because the redirect is relative so i get "main.aspx?..." instead of "http://www.tau.ac.il/Tal/Sys/main.aspx?..."

如何确定?

org.apache.http.ProtocolException: Invalid redirect URI: Sys/Main.aspx?id=021653167&sys=tal&rk=&dt=25/11/2011 8:50:56 AM
最佳回答

我找到了解决办法。

问题是,服务器正在对相对间接和<代码>faultHttpClient作出答复。 不能照此办理。 这是自我确定违约以来的。 HttpClient:

this.getParams().setParameter(ClientPNames.REJECT_RELATIVE_REDIRECT, false);

但是,既然它没有工作,我就决定试图对一个绝对地址作相对的回答,而我也做了工作。

你们都必须:

  1. 1. 创建一种习惯转手器,超越getLocation:

    class CustomRedirectHandler extends DefaultRedirectHandler {
        @Override
        public URI getLocationURI(HttpResponse response, HttpContext context)
                throws ProtocolException {
            response.setHeader("Location", "http://www.ims.tau.ac.il/Tal/"+ response.getFirstHeader("Location").getValue().replace(" ", "%20"));        
            return super.getLocationURI(response, context);
        }
    }
    

不是“http://www.ims.tau.ac.il/Tal/”,而是写上你自己档案的绝对基点。

例如,需要。 但是,服务器只是转向指数.html。 您在“http://www.google.com/”上将服务器所在地的答复与上述代码相同。

BTW the server was replying with spaces which again DefaultHttpClient had problem with so you replace spaces with %20 to get it to work.

  1. 1. 确立你的违约/cus HttpClient to use the new redirecthandler as this:

    httpClient.setRedirectHandler(new CustomRedirectHandler());
    
问题回答

也许,它确实如此。 检查 HttpResponse,如果你有 log,你可以进一步利用这一错误,而只是忽视这一错误。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签