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);




  • 相关阅读:
    PHP时间戳常用转换
    redis基本指令
    P2501 [HAOI2006]数字序列
    P2679 子串
    P2759 奇怪的函数
    P6823 「EZEC-4」zrmpaul Loves Array
    P6631 [ZJOI2020] 序列
    P2887 [USACO07NOV]Sunscreen G
    P3287 [SCOI2014]方伯伯的玉米田
    拓展欧几里得算法揭秘
  • 原文地址:https://www.cnblogs.com/plmmlp09/p/4274635.html
Copyright © 2011-2022 走看看