zoukankan      html  css  js  c++  java
  • Http部分

    首先是WebView部分,内嵌浏览器

     1 webView = (WebView) findViewById(R.id.web_view);
     2 webView.getSettings().setJavaScriptEnabled(true);
     3 webView.setWebViewClient(new WebViewClient() {
     4 @Override
     5 public boolean shouldOverrideUrlLoading(WebView view, String
     6 url) {
     7 view.loadUrl(url); // 根据传入的参数再去加载新的网页
     8 return true; // 表示当前WebView可以处理打开新网页的请求,不用借助
     9 系统浏览器
    10 }
    11 });
    12 webView.loadUrl("http://www.baidu.com");

    使用 HttpURLConnection

    1 URL url = new URL("http://www.baidu.com");
    2 HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    3 connection.setRequestMethod("GET");
    4 connection.setConnectTimeout(8000);
    5 connection.setReadTimeout(8000);
    6 InputStream in = connection.getInputStream();
    BufferedReader reader = new BufferedReader(new
    InputStreamReader(in));
    StringBuilder response = new StringBuilder();
    String line;
    while ((line = reader.readLine()) != null) {
    response.append(line);
    }


    connection.disconnect();

    使用 HttpClient
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet("http://www.baidu.com");
    httpClient.execute(httpGet);


    HttpPost httpPost = new HttpPost("http://www.baidu.com");
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("username", "admin"));
    params.add(new BasicNameValuePair("password", "123456"));
    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "utf-8");
    httpPost.setEntity(entity);
    httpClient.execute(httpPost);




  • 相关阅读:
    【2019/7/15】暑假自学——周进度报告
    用户体验评价
    《程序员修炼之道》读后感03
    《程序员修炼之道》读后感02
    《程序员修炼之道》读后感01
    《梦断代码》读后感03——为什么我们不能像造桥一样造软件
    《梦断代码》读后感02——问题的开始
    《梦断代码》读后感01——Chandle的开始
    第二阶段冲刺9
    十五周总结
  • 原文地址:https://www.cnblogs.com/plmmlp09/p/4274635.html
Copyright © 2011-2022 走看看