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

android开发连接网络

1、申请云服务器windows版
2、开通云服务器远程连接
3、通过远程桌面连接云服务器
4、在云服务器上安装Tomcat、cpolar内网穿透发布Tomcat服务器内容
5、android项目build.gradle注入依赖:
dependencies {

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation files('libs\\gson-2.9.1.jar')
implementation 'com.squareup.okhttp3:okhttp:3.5.0'
implementation 'com.squareup.okio:okio:1.11.0'

// implementation files(‘libs\glide-4.4.0.jar’)
implementation ‘com.nineoldandroids:library:2.4.0’
implementation ‘com.github.bumptech.glide:glide:3.7.0’
testImplementation ‘junit:junit:4.13.2’
androidTestImplementation ‘androidx.test.ext:junit:1.1.5’
androidTestImplementation ‘androidx.test.espresso:espresso-core:3.5.1’

}

重点是okhttp3:
implementation ‘com.squareup.okhttp3:okhttp:3.5.0’
implementation ‘com.squareup.okio:okio:1.11.0’

6、获取信息:
private void initData() {
OkHttpClient okHttpClient = new OkHttpClient();
Request request = new Request.Builder().url(WEB_SITE +
REQUEST_GOODS_URL).build();

    Call call = okHttpClient.newCall(request);Toast.makeText(MainActivity.this, call.request().toString(), Toast.LENGTH_LONG).show();

// 开启异步线程访问网络
call.enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
Log.i(“fff”,“kkkkkk”);
// Toast.makeText(MainActivity.this, response.toString(), Toast.LENGTH_LONG).show();
String res = response.body().string(); // 获取商品数据
Message msg = new Message();
msg.what = MSG_GOODS_OK;
msg.obj = res;
mHandler.sendMessage(msg);
}
@Override
public void onFailure(Call call, IOException e) {
Log.i(“fff”,“jjjjjjj”);

        }});
}

相关文章:

  • Leetcode—141.环形链表【简单】
  • csapp深入理解计算机系统 bomb lab(1)phase_1
  • Redis数据的持久化
  • SpringCloud Alibaba详解
  • NoSQL 与传统数据库的集成
  • WPF中如何在MVVM模式下关闭窗口
  • 大数据Doris(二十六):数据导入(Routine Load)介绍
  • 【大数据分布并行处理】单元测试(五)
  • Spring中有哪几种方法获取HttpSession对象
  • 4 redis的HyperLogLog入门原理
  • java发送媒体类型为multipart/form-data的请求
  • 云课五分钟-0Cg++默认版本和升级-std=c++17
  • 将 Fedora 38 平滑升级至 Fedora 39
  • 工厂设计模式
  • 聊聊logback的MDCFilter
  • [NodeJS] 关于Buffer
  • Angular 响应式表单之下拉框
  • angular2 简述
  • Angular4 模板式表单用法以及验证
  • Angular数据绑定机制
  • css布局,左右固定中间自适应实现
  • GraphQL学习过程应该是这样的
  • JS笔记四:作用域、变量(函数)提升
  • Linux编程学习笔记 | Linux多线程学习[2] - 线程的同步
  • PHP那些事儿
  • Python进阶细节
  • Spark RDD学习: aggregate函数
  • spring-boot List转Page
  • Travix是如何部署应用程序到Kubernetes上的
  • vue从入门到进阶:计算属性computed与侦听器watch(三)
  • 阿里中间件开源组件:Sentinel 0.2.0正式发布
  • 远离DoS攻击 Windows Server 2016发布DNS政策
  • 找一份好的前端工作,起点很重要
  • 06-01 点餐小程序前台界面搭建
  • ​DB-Engines 11月数据库排名:PostgreSQL坐稳同期涨幅榜冠军宝座
  • #Linux(Source Insight安装及工程建立)
  • #ubuntu# #git# repository git config --global --add safe.directory
  • (¥1011)-(一千零一拾一元整)输出
  • (06)金属布线——为半导体注入生命的连接
  • (20)目标检测算法之YOLOv5计算预选框、详解anchor计算
  • (接口自动化)Python3操作MySQL数据库
  • (十八)用JAVA编写MP3解码器——迷你播放器
  • (算法)Game
  • (一)RocketMQ初步认识
  • (转)JVM内存分配 -Xms128m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=512m
  • (转)重识new
  • ../depcomp: line 571: exec: g++: not found
  • .dwp和.webpart的区别
  • .NET CF命令行调试器MDbg入门(四) Attaching to Processes
  • .NET Standard 的管理策略
  • .NET/C# 使用反射注册事件
  • .NET6 开发一个检查某些状态持续多长时间的类
  • .NET学习教程二——.net基础定义+VS常用设置
  • [383] 赎金信 js
  • [Android Pro] Notification的使用