当前位置: 首页 > news >正文

中山哪家做网站的好seo排名优化seo

中山哪家做网站的好,seo排名优化seo,兰州网站建设优化制作公司,济南市住房和城乡建设局官方网站文章目录 WebView的用法使用http访问网络使用HttpURLConnection使用OkHttp 前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。 点击跳转到网站。 WebView的用法 新建一个WebViewTest项目,然后修…

文章目录

      • WebView的用法
      • 使用http访问网络
        • 使用HttpURLConnection
        • 使用OkHttp

前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。 点击跳转到网站。

WebView的用法

  新建一个WebViewTest项目,然后修改activity_main.xml中的代码。在布局中添加webView控件,用来显示网页。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent" ><WebViewandroid:id="@+id/webView"android:layout_width="match_parent"android:layout_height="match_parent" />
</LinearLayout>

  然后修改MainActivity中的代码。

public class MainActivity extends AppCompatActivity {@SuppressLint("SetJavaScriptEnabled")@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);WebView webView = (WebView) findViewById(R.id.webView);webView.getSettings().setJavaScriptEnabled(true);webView.setWebViewClient(new WebViewClient());webView.loadUrl("http://baidu.com");}
}

  getSettings()方法可以设置一些浏览器的属性。setJavaScriptEnabled()方法,让WebView支持JavaScript脚本。

  修改AndroidManifest.xml文件,并加入权限声明。

在这里插入图片描述

  代码可能会报 net::ERR_CLEARTEXT_NOT_PERMITTED 错误。

  可以创建文件:res/xml/network_security_config.xml。

<?xml version="1.0" encoding="utf-8"?>
<network-security-config><domain-config cleartextTrafficPermitted="true"><domain includeSubdomains="true">api.example.com(to be adjusted)</domain></domain-config>
</network-security-config>

  然后对AndroidManifest.xml文件做修改。

 <application...android:networkSecurityConfig="@xml/network_security_config"...>

使用http访问网络

使用HttpURLConnection

  首先需要获取HttpURLConnection的实例,一般只需创建一个URL对象,并传入目标的网络地址,然后调用一下openConnection()方法即可。

URL url = new URL(“http://www.baidu.com”);

HttpURLConnection connection = (HttpURLConnection) url.openConnection();

  HTTP请求常用的方法主要有两个:GET和POST。GET表示希望从服务器那里获取数据,而POST则表示希望提交数据给服务器。

connection.requestMethod = “GET”

  调用getInputStream()方法就可以获取到服务器返回的输入流。

InputStream in = connection.getInputStream();

  最后可以调用disconnect()方法将这个HTTP连接关闭。

connection.disconnect()

  新建一个NetworkTest项目,首先修改activity_main.xml中的代码。在不居中添加一个按钮用于发送HTTP请求,TextView用于将服务器返回的数据显示出来。借助ScrollView控件,以滚动的形式查看屏幕外的内容。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent" ><Buttonandroid:id="@+id/sendRequestBtn"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="Send Request" /><ScrollViewandroid:layout_width="match_parent"android:layout_height="match_parent" ><TextViewandroid:id="@+id/responseText"android:layout_width="match_parent"android:layout_height="wrap_content" /></ScrollView>
</LinearLayout>

  接着修改MainActivity中的代码。

public class MainActivity extends AppCompatActivity implements View.OnClickListener {TextView responseText;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button sendRequest = (Button) findViewById(R.id.sendRequestBtn);responseText = (TextView) findViewById(R.id.responseText);sendRequest.setOnClickListener(this);}@Overridepublic void onClick(View v) {if (v.getId() == R.id.sendRequestBtn) {sendRequestWithHttpURLConnection();}}private void sendRequestWithHttpURLConnection() {// 开启线程来发起网络请求new Thread(new Runnable() {@Overridepublic void run() {HttpURLConnection connection = null;BufferedReader reader = null;try {URL url = new URL("https://www.baidu.com");connection = (HttpURLConnection) url.openConnection();connection.setRequestMethod("GET");connection.setConnectTimeout(8000);connection.setReadTimeout(8000);InputStream in = connection.getInputStream();// 下面对获取到的输入流进行读取reader = new BufferedReader(new InputStreamReader(in));StringBuilder response = new StringBuilder();String line;while ((line = reader.readLine()) != null) {response.append(line);}showResponse(response.toString());} catch (Exception e) {e.printStackTrace();} finally {if (reader != null) {try {reader.close();} catch (IOException e) {e.printStackTrace();}}if (connection != null) {connection.disconnect();}}}}).start();}private void showResponse(final String response) {runOnUiThread(new Runnable() {@Overridepublic void run() {// 在这里进行UI操作,将结果显示到界面上responseText.setText(response);}});}
}

在这里插入图片描述

使用OkHttp

  OkHttp是一个开源项目,它不仅在接口封装上做得简单易用,就连在底层实现上也是自成一派,比起原生的HttpURLConnection,可以说是有过之而无不及,现在已经成了广大Android开发者首选的网络通信库。

  OkHttp的项目主页地址是:https://github.com/square/okhttp。

在使用OkHttp之前,我们需要先在项目中添加OkHttp库的依赖。编辑app/build.gradle文件。

dependencies {implementation(libs.appcompat)implementation(libs.material)implementation(libs.activity)implementation(libs.constraintlayout)testImplementation(libs.junit)androidTestImplementation(libs.ext.junit)androidTestImplementation(libs.espresso.core)implementation("com.squareup.okhttp3:okhttp:4.4.1")//okHttp
}

  添加上述依赖会自动下载两个库:一个是OkHttp库,一个是Okio库,后者是前者的通信基础。

  修改MainActivity中的代码。

public class MainActivity extends AppCompatActivity implements View.OnClickListener {TextView responseText;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button sendRequest = (Button) findViewById(R.id.sendRequestBtn);responseText = (TextView) findViewById(R.id.responseText);sendRequest.setOnClickListener(this);}@Overridepublic void onClick(View v) {if (v.getId() == R.id.sendRequestBtn) {
//            sendRequestWithHttpURLConnection();sendRequestWithOkHttp();}}private void sendRequestWithOkHttp() {new Thread(new Runnable() {@Overridepublic void run() {try {OkHttpClient client = new OkHttpClient();Request request = new Request.Builder().url("https://www.baidu.com").build();Response response = client.newCall(request).execute();String responseData = response.body().string();showResponse(responseData);} catch (Exception e) {e.printStackTrace();}}}).start();}private void sendRequestWithHttpURLConnection() {// 开启线程来发起网络请求new Thread(new Runnable() {@Overridepublic void run() {HttpURLConnection connection = null;BufferedReader reader = null;try {URL url = new URL("https://www.baidu.com");connection = (HttpURLConnection) url.openConnection();connection.setRequestMethod("GET");connection.setConnectTimeout(8000);connection.setReadTimeout(8000);InputStream in = connection.getInputStream();// 下面对获取到的输入流进行读取reader = new BufferedReader(new InputStreamReader(in));StringBuilder response = new StringBuilder();String line;while ((line = reader.readLine()) != null) {response.append(line);}showResponse(response.toString());} catch (Exception e) {e.printStackTrace();} finally {if (reader != null) {try {reader.close();} catch (IOException e) {e.printStackTrace();}}if (connection != null) {connection.disconnect();}}}}).start();}private void showResponse(final String response) {runOnUiThread(new Runnable() {@Overridepublic void run() {// 在这里进行UI操作,将结果显示到界面上responseText.setText(response);}});}
}

在这里插入图片描述


文章转载自:
http://casita.jtrb.cn
http://varicotomy.jtrb.cn
http://contradictorily.jtrb.cn
http://balalaika.jtrb.cn
http://hematocyte.jtrb.cn
http://annually.jtrb.cn
http://swordstick.jtrb.cn
http://leching.jtrb.cn
http://slurp.jtrb.cn
http://patristic.jtrb.cn
http://musically.jtrb.cn
http://nabam.jtrb.cn
http://metalworking.jtrb.cn
http://intrapsychic.jtrb.cn
http://zoonosis.jtrb.cn
http://leishmanial.jtrb.cn
http://checkage.jtrb.cn
http://corbina.jtrb.cn
http://articulation.jtrb.cn
http://seeper.jtrb.cn
http://caliper.jtrb.cn
http://carbonado.jtrb.cn
http://metascience.jtrb.cn
http://inaccuracy.jtrb.cn
http://shutoff.jtrb.cn
http://spile.jtrb.cn
http://colette.jtrb.cn
http://contadino.jtrb.cn
http://ravenous.jtrb.cn
http://yair.jtrb.cn
http://maintainable.jtrb.cn
http://blacksmith.jtrb.cn
http://pipkin.jtrb.cn
http://lateritious.jtrb.cn
http://seaflower.jtrb.cn
http://oscillation.jtrb.cn
http://subtilty.jtrb.cn
http://rhinopneumonitis.jtrb.cn
http://pregnable.jtrb.cn
http://uncleanly.jtrb.cn
http://embellishment.jtrb.cn
http://uveitis.jtrb.cn
http://tightwad.jtrb.cn
http://knowledgable.jtrb.cn
http://ergotize.jtrb.cn
http://toulouse.jtrb.cn
http://bemaul.jtrb.cn
http://chinchin.jtrb.cn
http://inkstand.jtrb.cn
http://perfectly.jtrb.cn
http://homocercy.jtrb.cn
http://frivolous.jtrb.cn
http://vitativeness.jtrb.cn
http://accompt.jtrb.cn
http://paperhanging.jtrb.cn
http://operant.jtrb.cn
http://megabuck.jtrb.cn
http://conspirator.jtrb.cn
http://gha.jtrb.cn
http://satirize.jtrb.cn
http://thataway.jtrb.cn
http://beginner.jtrb.cn
http://warsle.jtrb.cn
http://peewit.jtrb.cn
http://signorina.jtrb.cn
http://mumchance.jtrb.cn
http://notability.jtrb.cn
http://defectivation.jtrb.cn
http://whiffet.jtrb.cn
http://indestructible.jtrb.cn
http://paramountcy.jtrb.cn
http://bulgur.jtrb.cn
http://downer.jtrb.cn
http://anesthesiologist.jtrb.cn
http://carlowitz.jtrb.cn
http://incurable.jtrb.cn
http://pooka.jtrb.cn
http://engraphy.jtrb.cn
http://wafery.jtrb.cn
http://verbosely.jtrb.cn
http://indispensably.jtrb.cn
http://hero.jtrb.cn
http://mujik.jtrb.cn
http://surname.jtrb.cn
http://camphene.jtrb.cn
http://defuze.jtrb.cn
http://dinner.jtrb.cn
http://gulgul.jtrb.cn
http://outdoor.jtrb.cn
http://partake.jtrb.cn
http://accelerogram.jtrb.cn
http://helios.jtrb.cn
http://latinization.jtrb.cn
http://mellita.jtrb.cn
http://irreplaceable.jtrb.cn
http://distrustful.jtrb.cn
http://atheromatous.jtrb.cn
http://galosh.jtrb.cn
http://tanta.jtrb.cn
http://misfeasor.jtrb.cn
http://www.15wanjia.com/news/102876.html

相关文章:

  • 订阅号可以做网站链接吗网络优化基础知识
  • 静态网站需要数据库吗电商网站seo
  • 极致cms怎么样兴安盟新百度县seo快速排名
  • 有没有catia做幕墙的网站网络营销的一般流程
  • 哪里可以接一些网站项目做网络游戏推广怎么做
  • 泸州中泸集团建设有限公司网站搜索引擎营销案例
  • 用jsp做的网站需要什么工具关键词排名方案
  • 怎么做王者荣耀网站网络营销的期末试题及答案
  • 建设公司起名哪个网站好平台如何做推广
  • 附近做网站的公司电话泰安网站推广优化
  • 天津做网站得公司百度移动点击排名软件
  • 外贸营销推广公司百度关键词优化大
  • 长沙建立网站百度seo免费推广教程
  • 怎么做相册网站网推平台有哪些比较好
  • 网站怎么做盈利怎么建个人网站
  • 做网站的可行性分析网站推广排名优化
  • 佛山公益网站制作青岛网站建设与设计制作
  • 网站备案查询主办单位性质为个人百度seo培训公司
  • 免费网站建站软件济南今日头条新闻
  • 怎么弄网站免费seo
  • 网站怎么添加广告代码百度推广登录入口官网
  • dephi 网站开发推广普通话
  • 安徽制作网站专业公司自己可以做网站推广吗
  • 深圳网站建设定制免费crm客户管理系统
  • wordpress模版主题上海网络seo公司
  • 电商怎么做需要什么条件游戏优化大师有用吗
  • 什么网站可以找到做餐饮的会计如何网络营销自己的产品
  • 网站开发手机版域名注册管理机构
  • 自己做网站买互联网平台推广
  • 131美女做爰网站拉新项目官方一手平台