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

情感网站seo个人网站什么语言做

情感网站seo,个人网站什么语言做,安徽省途顺建设工程有限公司网站,做农产品的网站网络操作 Android平台下的原生网络操作可以分为以下几步#xff1a; 创建URL对象#xff1b;通过URL对象获取HttpURLConnection对象#xff1b;通过HttpURLConnection对象设置请求头键值对、网络连接超时时间等#xff1b;通过HttpURLConnection对象的connect()方法建立网…网络操作 Android平台下的原生网络操作可以分为以下几步 创建URL对象通过URL对象获取HttpURLConnection对象通过HttpURLConnection对象设置请求头键值对、网络连接超时时间等通过HttpURLConnection对象的connect()方法建立网络连接通过响应码判断请求是否成功如果成功的话获取输入流对返回的结果进行处理并显示 这里要注意的是网络请求操作不能直接放在ui线程中需要另外开启一个线程去处理网络请求因为网络请求操作是一个耗时的操作。 布局文件 ?xml version1.0 encodingutf-8? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parenttools:context.MainActivityandroid:orientationverticalButtonandroid:idid/btn_sendgetandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:text点击发送get请求/Buttonandroid:idid/btn_sendpostandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:text点击发送post请求/TextViewandroid:idid/tvandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:scrollbarsverticalandroid:fadeScrollbarsfalse//LinearLayoutGET请求 这里说一下用到的方法的作用 setConnectTimeout设置请求超时时间 setRequestMethod设置请求方法 setRequestProperty设置请求属性 connect()建立网络连接 getResponseCode()获取响应码 try {new Thread(new Runnable() {Overridepublic void run() {try {URL url new URL(http://www.imooc.com/api/teacher?type2page1);HttpURLConnection connection (HttpURLConnection)url.openConnection();connection.setConnectTimeout(30*1000);connection.setRequestMethod(GET);connection.setRequestProperty(Content-Type,application/json);connection.setRequestProperty(Charset,UTF-8);connection.setRequestProperty(Accept-Charset,UTF-8);connection.connect();int responseCode connection.getResponseCode();//如果请求成功if (responseCode HttpURLConnection.HTTP_OK) {//获取输入流InputStream inputStream connection.getInputStream();byte[] bytes new byte[1024];StringBuffer result new StringBuffer();int len 0;while ((len inputStream.read(bytes)) ! -1) {result.append(new String(bytes,0,len));}//不能直接在其它线程更新ui线程可以使用此方法或者使用handlerrunOnUiThread(new Runnable() {Overridepublic void run() {tv.setText(result);}});Log.d(TAG, onClick: result);}}catch (Exception e) {e.printStackTrace();}}}).start();} catch (Exception e) {e.printStackTrace();}POST请求 new Thread(new Runnable() {Overridepublic void run() {try {URL url new URL(http://www.imooc.com/api/teacher?type2page1);HttpURLConnection connection (HttpURLConnection) url.openConnection();connection.setConnectTimeout(30 * 1000);connection.setRequestProperty(Content-Type,application/json);connection.setRequestProperty(Charset,UTF-8);connection.setRequestProperty(Accept-Charset,UTF-8);connection.connect();int responseCode connection.getResponseCode();if (responseCode HttpURLConnection.HTTP_OK) {InputStream inputStream connection.getInputStream();int len 0;byte[] bytes new byte[1024];StringBuffer result new StringBuffer();while ((len inputStream.read(bytes)) ! -1) {result.append(new String(bytes,0,len));}Log.d(TAG, responseCode: responseCode);Log.d(TAG, result: result);runOnUiThread(new Runnable() {Overridepublic void run() {tv.setText(result);}});} else {Log.d(TAG, responseCode: responseCode);}} catch (MalformedURLException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}}).start();解析返回的json数据 public ListLesson JsonToArray(String str) {ListLesson lessonList new ArrayList();try {JSONObject jsonObject new JSONObject(str);JSONArray jsonArray jsonObject.getJSONArray(data);for (int i 0; i jsonArray.length(); i) {JSONObject lesson (JSONObject) jsonArray.get(i);int id lesson.getInt(id);int learner lesson.getInt(learner);String name lesson.getString(name);String picSmall lesson.getString(picSmall);String picBig lesson.getString(picBig);String description lesson.getString(description);Lesson lesson1 new Lesson();lesson1.setId(id);lesson1.setDescription(description);lesson1.setLearner(learner);lesson1.setPicBig(picBig);lesson1.setPicSmall(picSmall);lesson1.setName(name);lessonList.add(lesson1);}} catch (JSONException e) {e.printStackTrace();}return lessonList;}注意事项 Android9.0以后使用http访问网络需要添加配置文件首先在res目录下新建一个xml资源目录然后创建配置文件配置文件的名称必须是neteork_security_config.xml 内容 ?xml version1.0 encodingutf-8? network-security-config!--允许http请求的加载--base-config cleartextTrafficPermitted true/ /network-security-config
http://www.w-s-a.com/news/692356/

相关文章:

  • 室内设计公司 网站建设建站塔山双喜
  • 网站建设属于什么经营范围销售网站开发业务
  • 企业建站系统平台优秀网站作品截图
  • 杭州品牌网站制作wordpress多域名移动主题
  • 北京网站网站建设icp备案 网站备案
  • 长春网站公司哪家好电子商务网站建设作文
  • 网站开发php程序员网上店铺怎么运营
  • mip网站怎么做匹配h5婚纱摄影网站模板
  • 怎么注册建设公司网站域名历史价格查询
  • 爱站网seo工具包互联网软件开发工程师
  • 百度站长工具平台登录郑州seo规则
  • 财税公司做网站精品建站教程
  • 建设区块链网站区块链开发平台有哪些
  • 青年人爱看的网站ie显示wordpress网页不完整
  • 优惠券推广网站怎么做青岛正规网站建设哪家便宜
  • 怎么搞一个服务器建设网站wordpress页眉编辑
  • 计算机企业网站建设论文流量平台是什么意思
  • 成都建设网站公司哪家好上海有名的广告公司
  • 收录优美图片找不到了整站seo优化一般多少钱
  • 大型网站建设哪家好汉川网页设计
  • 深圳品牌策划公司推荐南昌网站怎么做seo
  • 滨州做微商城网站备案时暂时关闭网站
  • 手机网站样式代码网站是怎样制作的
  • 任务发布网站建设苏州园区房价
  • 网站的认识知识付费做的最好的平台
  • 企业电子商务网站设计的原则深圳的网站建设公司怎么样
  • 个人网站趋向wordpress图片搬家
  • 做空压机网站的公司有哪些wordpress 外部链接
  • 网站建设管理成本估计小红书推广平台
  • 一级a做爰片免费观看网站焦作建设企业网站公司