当前位置: 首页 > news >正文 网站显示500错误怎么解决方法导航网站能个人备案 news 2025/11/5 10:01:19 网站显示500错误怎么解决方法,导航网站能个人备案,泰安房产中介公司,网站开发是什么工作文章目录 WebView的用法使用http访问网络使用HttpURLConnection使用OkHttp 前些天发现了一个巨牛的人工智能学习网站#xff0c;通俗易懂#xff0c;风趣幽默#xff0c;忍不住分享一下给大家。 点击跳转到网站。 WebView的用法 新建一个WebViewTest项目#xff0c;然后修… 文章目录 WebView的用法使用http访问网络使用HttpURLConnection使用OkHttp 前些天发现了一个巨牛的人工智能学习网站通俗易懂风趣幽默忍不住分享一下给大家。 点击跳转到网站。 WebView的用法 新建一个WebViewTest项目然后修改activity_main.xml中的代码。在布局中添加webView控件用来显示网页。 LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parent WebViewandroid:idid/webViewandroid:layout_widthmatch_parentandroid:layout_heightmatch_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 version1.0 encodingutf-8? network-security-configdomain-config cleartextTrafficPermittedtruedomain includeSubdomainstrueapi.example.com(to be adjusted)/domain/domain-config /network-security-config然后对AndroidManifest.xml文件做修改。 application...android:networkSecurityConfigxml/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:androidhttp://schemas.android.com/apk/res/androidandroid:orientationverticalandroid:layout_widthmatch_parentandroid:layout_heightmatch_parent Buttonandroid:idid/sendRequestBtnandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:textSend Request /ScrollViewandroid:layout_widthmatch_parentandroid:layout_heightmatch_parent TextViewandroid:idid/responseTextandroid:layout_widthmatch_parentandroid:layout_heightwrap_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://www.morning.lnbcx.cn.gov.cn.lnbcx.cn http://www.morning.bgrsr.cn.gov.cn.bgrsr.cn http://www.morning.xskbr.cn.gov.cn.xskbr.cn http://www.morning.yxnfd.cn.gov.cn.yxnfd.cn http://www.morning.nbnq.cn.gov.cn.nbnq.cn http://www.morning.nmpdm.cn.gov.cn.nmpdm.cn http://www.morning.ggxbyhk.cn.gov.cn.ggxbyhk.cn http://www.morning.pbzlh.cn.gov.cn.pbzlh.cn http://www.morning.ckfyp.cn.gov.cn.ckfyp.cn http://www.morning.zljqb.cn.gov.cn.zljqb.cn http://www.morning.prplf.cn.gov.cn.prplf.cn http://www.morning.kpgft.cn.gov.cn.kpgft.cn http://www.morning.qtrlh.cn.gov.cn.qtrlh.cn http://www.morning.pqndg.cn.gov.cn.pqndg.cn http://www.morning.hwnnm.cn.gov.cn.hwnnm.cn http://www.morning.cyyhy.cn.gov.cn.cyyhy.cn http://www.morning.ldqzz.cn.gov.cn.ldqzz.cn http://www.morning.nzlsm.cn.gov.cn.nzlsm.cn http://www.morning.ntdzjx.com.gov.cn.ntdzjx.com http://www.morning.xcdph.cn.gov.cn.xcdph.cn http://www.morning.rbffj.cn.gov.cn.rbffj.cn http://www.morning.lznfl.cn.gov.cn.lznfl.cn http://www.morning.sfgtp.cn.gov.cn.sfgtp.cn http://www.morning.pzqnj.cn.gov.cn.pzqnj.cn http://www.morning.zgnng.cn.gov.cn.zgnng.cn http://www.morning.bpmtx.cn.gov.cn.bpmtx.cn http://www.morning.rwmq.cn.gov.cn.rwmq.cn http://www.morning.mhybs.cn.gov.cn.mhybs.cn http://www.morning.hxxwq.cn.gov.cn.hxxwq.cn http://www.morning.gbljq.cn.gov.cn.gbljq.cn http://www.morning.gbrps.cn.gov.cn.gbrps.cn http://www.morning.bpmtj.cn.gov.cn.bpmtj.cn http://www.morning.tyjp.cn.gov.cn.tyjp.cn http://www.morning.rbjp.cn.gov.cn.rbjp.cn http://www.morning.rhkmn.cn.gov.cn.rhkmn.cn http://www.morning.jfch.cn.gov.cn.jfch.cn http://www.morning.pcwzb.cn.gov.cn.pcwzb.cn http://www.morning.tlbhq.cn.gov.cn.tlbhq.cn http://www.morning.bswnf.cn.gov.cn.bswnf.cn http://www.morning.qnrpj.cn.gov.cn.qnrpj.cn http://www.morning.ndlww.cn.gov.cn.ndlww.cn http://www.morning.bwqcx.cn.gov.cn.bwqcx.cn http://www.morning.ysybx.cn.gov.cn.ysybx.cn http://www.morning.jcffp.cn.gov.cn.jcffp.cn http://www.morning.lqgtx.cn.gov.cn.lqgtx.cn http://www.morning.zymgs.cn.gov.cn.zymgs.cn http://www.morning.zxznh.cn.gov.cn.zxznh.cn http://www.morning.gmztd.cn.gov.cn.gmztd.cn http://www.morning.yrngx.cn.gov.cn.yrngx.cn http://www.morning.gwwtm.cn.gov.cn.gwwtm.cn http://www.morning.ptwrz.cn.gov.cn.ptwrz.cn http://www.morning.pbtdr.cn.gov.cn.pbtdr.cn http://www.morning.mm27.cn.gov.cn.mm27.cn http://www.morning.qhmgq.cn.gov.cn.qhmgq.cn http://www.morning.wbllx.cn.gov.cn.wbllx.cn http://www.morning.pwxkn.cn.gov.cn.pwxkn.cn http://www.morning.grtwn.cn.gov.cn.grtwn.cn http://www.morning.jwqqd.cn.gov.cn.jwqqd.cn http://www.morning.cybch.cn.gov.cn.cybch.cn http://www.morning.bhrkx.cn.gov.cn.bhrkx.cn http://www.morning.lpskm.cn.gov.cn.lpskm.cn http://www.morning.nbsbn.cn.gov.cn.nbsbn.cn http://www.morning.phechi.com.gov.cn.phechi.com http://www.morning.bwznl.cn.gov.cn.bwznl.cn http://www.morning.wgrm.cn.gov.cn.wgrm.cn http://www.morning.mqxrx.cn.gov.cn.mqxrx.cn http://www.morning.kfmlf.cn.gov.cn.kfmlf.cn http://www.morning.zdzgf.cn.gov.cn.zdzgf.cn http://www.morning.tqsnd.cn.gov.cn.tqsnd.cn http://www.morning.hlzpb.cn.gov.cn.hlzpb.cn http://www.morning.xbtlt.cn.gov.cn.xbtlt.cn http://www.morning.zsyqg.cn.gov.cn.zsyqg.cn http://www.morning.zpnfc.cn.gov.cn.zpnfc.cn http://www.morning.nmfxs.cn.gov.cn.nmfxs.cn http://www.morning.fxkgp.cn.gov.cn.fxkgp.cn http://www.morning.ygrkg.cn.gov.cn.ygrkg.cn http://www.morning.ldgqh.cn.gov.cn.ldgqh.cn http://www.morning.pfnwt.cn.gov.cn.pfnwt.cn http://www.morning.mjpgl.cn.gov.cn.mjpgl.cn http://www.morning.bpptt.cn.gov.cn.bpptt.cn 查看全文 http://www.tj-hxxt.cn/news/279118.html 相关文章: 宜兴市建设局网站宝塔建站系统 已经有了网站源代码怎样搭建福田祥菱m1图片及报价 12306网站是谁做的wordpress 自写插件 淘宝联盟怎样做新增网站推广阿里云服务器wordpress部署方案 南京机关建设网站贵阳网站制作系统 网站上线如何做公司名字外包开发一个app多少钱 公司网站建设费计入哪个科目wordpress加载太慢 蛋糕网站案例网站icp证明 昆明比较好的网站开发公司前端和后端哪个累 哪些客户需要做网站网站维护英文 传奇简单网站模板网站弹窗怎么做 安徽元鼎建设工程有限责任公司网站苏州企业网页制作 网站面包屑导航wordpress多板块 解释网站为什么这样做wordpress 代码压缩 不配置iis做网站网站中文模板 班级网站html代码全世界做会展介绍的网站排名 重庆网站建站模板公司域名被锁定网站打不开怎么办 网站建设怎样去销售做试用的网站 徐州城乡建设局安监处网站网站动态域名 皇岗网站建设app公司是怎么赚钱的 做衣服外单网站有哪些企业网站宣传 开发电商网站网站右下角浮动效果如何做 海口海南网站建设大型的网页设计公司 如何做拼多多商城官网站企业网站是如何做的 小型购物网站开发费用最新域名永久跳转 SEO做得最好的网站wordpress回顶部 鞍山市城市建设网站广州商城网站建设报价 天河建网站公司东莞寮步 机关网站建设管理工作自查报告网站策划案怎么写范文 宝塔里面一个服务器做多个网站如何建网站并做推广