2014-03-28 6 views

답변

0

안드로이드 4.0 웹킷은 네이티브 크롬 http 모듈을 사용하여 모든 http/https 요청을 실행합니다. Java 레이어가 가로 채기위한 후크 또는 콜백을 제공하지 않습니다.

전에 전에 요청을 가로 채고 싶지 않다면 웹킷을 통해 전송 된 다음 WebViewClient.shouldOverrideUrlLoading()을 참조하십시오.

0

리소스를 얻는 방법에 대한 답변이 없지만 webview에서 세션 쿠키를 가져 와서 자신의 http-Requests 또는 Android Download-Manager에서 사용할 수 있습니다.

나는 예를 만 쿠키에서 PHP-sessionID와 당신이 이런 사용할 수 있습니다

static final private String phpSessionName    = "PHPSESSID"; 


/** 
* Loads PHP Session ID from Cookie 
* 
* @date 22.09.2015 
* @version 1.0 
* @param url   
* @return PHP SessionID or NULL if cookie contains no SessionID 
*/ 
protected String getPHPSessionID(String url) 
{ 
    String id = null; 


    CookieManager cookieManager = CookieManager.getInstance(); 
    String cookie    = cookieManager.getCookie(url); 
    if(cookie != null) 
    { 
    String[] cookie_parts = cookie.split(";"); 
    for(int t=0;t < cookie_parts.length;t++) 
    { 
     String[] cookieContent = cookie_parts[t].split("="); 
     if(phpSessionName.equals(cookieContent[0])) 
     { 
     id = cookieContent[1];   
      break; 
     } 
    } 
    } 
    else Log.w(TAG, "getPHPSessionID: no cookie found");  

    return id; 
} 

(이것은 대부분의 PHP가 좋아 측면에 로그인에 사용되는) 무엇이 :

String phpSession = getPHPSessionID("http://yourdomain.com");  
if(phpSession != null) { 
    DefaultHttpClient client = new DefaultHttpClient(); 
    HttpGet request = new HttpGet("http://yourdomain.com/stuff-to-load"); 
    response = client.execute(request); 

    // Your code to load data or headers or response 
    request.addHeader("Cookie",phpSessionName+"="+phpSession); 
} 

Httpclient를 사용하지 않으려는 경우 사용되지 않으므로 UrlConnection이나 다른 Http 클라이언트에서도이 세션 쿠키를 사용할 수 있습니다. 쿠키 헤더 만 추가하면됩니다.

관련 문제