开发者

HTTPCLIENT: Authentication for https protocol on an asp page

I need to access an asp page running on 'https' protocol. I am facing problems at authentication part itself. The response object returns "HTTP/1.1 200 OK" but i am getting redirected to Login page itself.

Following is my code:

public FileDownloadHttpWrapper(String url,String username, String password)
{
    SchemeRegistry supportedSchemes = new SchemeRegistry();
    supportedSchemes.register(new Scheme("https", 
    SSLSocketFactory.getSocketFactory(), 443));

    // prepare parameters
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "UTF-8");
    HttpProtocolParams.setUseExpectContinue(params, true);

    ClientConnectionManager ccm = new ThreadSafeClientConnManager(params,supportedSchemes);
    mClient = ne开发者_StackOverfloww DefaultHttpClient(ccm,params);            
    mClient.getCredentialsProvider().setCredentials(
        new AuthScope(null,AuthScope.ANY_PORT),
        new UsernamePasswordCredentials(username, password)
        );
}

private Object getRequest(String url)
{
    HttpGet get = new HttpGet("/EvalMuniMKT/mainmenu.asp");
    HttpHost target = new HttpHost(url, 443, "https");

    try
    {
        // execute the GET
        HttpResponse resp = mClient.execute(target,get);

        HttpEntity entity = resp.getEntity();

        System.out.println(resp.getStatusLine());            
        System.out.println(EntityUtils.toString(entity));   
    } 
    catch(Exception ex)
    {
        ex.printStackTrace();
    }
    finally
    {
        // release any connection resources used by the method    
    }

    return null;
}


I think the asp site uses form based login (session), not http basic authentication. For that you may need to do login form post and hold cookie in context and pass the context while executing the actual request.

something like :

        CookieStore cookieStore = new BasicCookieStore();
    // Create local HTTP context
    HttpContext localContext = new BasicHttpContext();
    // Bind custom cookie store to the local context
    localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
          hc.execute(httpget, localContext);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜