webView를 이용해 개발중인 웹사이트를 띄우는거는 정상이나
웹쪽에 전반적인지식이 부족한 상태에서 알아보면서 개발진행중입니다.
우선 헤더 부분을 찍어서 클라이언트 쪽에서 요청 시 관련 정보를 띄우는 식 으로 이해를 하고 진행하려고 많은 자료를 찾아서 진행해 보았으나 정상적인 작동이 안되는문제 때문에 질문드립니다.
우선적으로 제가 진행해본 방법은
private void getHeader() {
new Thread(new Runnable() {
@Override
public void run() {
try {
headerURL = new URL(url);
URLConnection conn = headerURL.openConnection();
Map<String, List<String>> headers = conn.getHeaderFields();
for(Map.Entry<String, List<String>> entry : headers.entrySet()) {
Log.e("Key : "+ entry.getKey() , " Value : " + entry.getValue());
}
} catch (MalformedURLException e) {
Log.e("HeaderUrl Error", "HeaderUrl Parse Error");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
이런식으로 메소드 구현후 진행 해보았습니다. 스레드를 미사용시 http exception 으로 thread를 사용해 진행 했습니다.
허나 웹 url페이지는 정상적으로 나타났으나 log가 안직혀서 진행할수가 없었습니다. 또 찾아본 부분은
webView.setWebViewClient(viewClient);
viewClient.shouldOverrideUrlLoading(webView, url);
웹뷰에 webviewClient를 별도로 구현해서 진행 하는방법을 보고 진행해봣으나 이번꺼는 url페이지 조차 동작을 하지 안습니다.
public class HeaderWebViewClient extends WebViewClient {
private URL url;
private URLConnection conn;
@Override
public boolean shouldOverrideUrlLoading(final WebView view, final String urlAddr) {
Log.e("HeaderWebView headerSetting","");
new Thread(new Runnable() {
@Override
public void run() {
try {
url = new URL(urlAddr);
conn = url.openConnection();
conn.setConnectTimeout(3000);
conn.setRequestProperty("valuekey", "ddddd");
conn.connect();
// get the size of the file which is in the header of the request
int size = conn.getContentLength();
}catch (Exception e) {
// TODO: handle exception
}
String htmlContent = "";
HttpGet httpGet = new HttpGet(urlAddr);
// this receives the response
HttpResponse response;
HttpClient httpclient = new DefaultHttpClient();
try {
response = httpclient.execute(httpGet);
if (response.getStatusLine().getStatusCode() == 200) {
// la conexion fue establecida, obtener el contenido
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream inputStream = entity.getContent();
StringBuffer out = new StringBuffer();
byte[] b = new byte[4096];
for (int n; (n = inputStream.read(b)) != -1;) {
out.append(new String(b, 0, n));
}
htmlContent = out.toString();
}
}
} catch (Exception e) {}
view.loadData(htmlContent, "text/html", "utf-8");
}
});
return true;
}
}
이런식의 구현방법 이였습니다.
webview내부에서 요청에 대한 부분을 디바이스에서 헤더라는것을 찾아오는 방법에 대해 혹시 진행해보신분 계시다면 도움부탁드립니다.