鸿蒙OS开发实例:【窥探网络请求】

news2024/7/6 19:42:33

 HarmonyOS 平台中使用网络请求,需要引入 "@ohos.net.http", 并且需要在 module.json5 文件中申请网络权限, 即 “ohos.permission.INTERNET”

本篇文章将尝试使用 @ohos.net.http 来实现网络请求

场景设定

  1. WeiBo UniDemo HuaWei : 请求顺序
  2. WeiBo1 UniDemo2 HuaWei3 : 异步/同步请求时,序号表示请求回来的顺序
  3. “开始网络请求-异步” : 开始异步请求
  4. “开始网络请求-同步” : 开始同步请求
  5. “开始网络请求-自定义方法装饰器” : 采用自定义方法装饰器进行传参,进而完成网络请求

官方网络请求案例

注意:

每次请求都必须新创建一个HTTP请求实例,即只要发起请求,必须调用createHttp方法

更多鸿蒙开发应用知识已更新qr23.cn/AKFP8k参考前往。

搜狗高速浏览器截图20240326151547.png

关于 @ohos.net.http 有三个request方法

  1. request(url: string, callback: AsyncCallback): void;

    1.1 如下“官方指南代码缩减版”使用到了这个方法

  2. request(url: string, options: HttpRequestOptions, callback: AsyncCallback): void;

    2.1 如下“官方指南代码” 使用了这个方法

  3. request(url: string, options?: HttpRequestOptions): Promise;

    3.1 将在后续实践代码中使用到

// 引入包名
import http from '@ohos.net.http';

// 每一个httpRequest对应一个HTTP请求任务,不可复用
let httpRequest = http.createHttp();
// 用于订阅HTTP响应头,此接口会比request请求先返回。可以根据业务需要订阅此消息
// 从API 8开始,使用on('headersReceive', Callback)替代on('headerReceive', AsyncCallback)。 8+
httpRequest.on('headersReceive', (header) => {
    console.info('header: ' + JSON.stringify(header));
});
httpRequest.request(
    // 填写HTTP请求的URL地址,可以带参数也可以不带参数。URL地址需要开发者自定义。请求的参数可以在extraData中指定
    "EXAMPLE_URL",
    {
        method: http.RequestMethod.POST, // 可选,默认为http.RequestMethod.GET
        // 开发者根据自身业务需要添加header字段
        header: {
            'Content-Type': 'application/json'
        },
        // 当使用POST请求时此字段用于传递内容
        extraData: {
            "data": "data to send",
        },
        expectDataType: http.HttpDataType.STRING, // 可选,指定返回数据的类型
        usingCache: true, // 可选,默认为true
        priority: 1, // 可选,默认为1
        connectTimeout: 60000, // 可选,默认为60000ms
        readTimeout: 60000, // 可选,默认为60000ms
        usingProtocol: http.HttpProtocol.HTTP1_1, // 可选,协议类型默认值由系统自动指定
    }, (err, data) => {
        if (!err) {
            // data.result为HTTP响应内容,可根据业务需要进行解析
            console.info('Result:' + JSON.stringify(data.result));
            console.info('code:' + JSON.stringify(data.responseCode));
            // data.header为HTTP响应头,可根据业务需要进行解析
            console.info('header:' + JSON.stringify(data.header));
            console.info('cookies:' + JSON.stringify(data.cookies)); // 8+
        } else {
            console.info('error:' + JSON.stringify(err));
            // 取消订阅HTTP响应头事件
            httpRequest.off('headersReceive');
            // 当该请求使用完毕时,调用destroy方法主动销毁
            httpRequest.destroy();
        }
    }
);
// 引入包名
import http from '@ohos.net.http';

// 每一个httpRequest对应一个HTTP请求任务,不可复用
let httpRequest = http.createHttp();

httpRequest.request(
    // 填写HTTP请求的URL地址,可以带参数也可以不带参数。URL地址需要开发者自定义。请求的参数可以在extraData中指定
    "EXAMPLE_URL",
    (err, data) => {
        if (!err) {
            // data.result为HTTP响应内容,可根据业务需要进行解析
            console.info('Result:' + JSON.stringify(data.result));
            console.info('code:' + JSON.stringify(data.responseCode));
            // data.header为HTTP响应头,可根据业务需要进行解析
            console.info('header:' + JSON.stringify(data.header));
            console.info('cookies:' + JSON.stringify(data.cookies)); // 8+
        } else {
            console.info('error:' + JSON.stringify(err));
            // 取消订阅HTTP响应头事件
            httpRequest.off('headersReceive');
            // 当该请求使用完毕时,调用destroy方法主动销毁
            httpRequest.destroy();
        }
    }
);

场景布局

基础页面组件代码

考虑到实际的场景会用到网络请求加载,因此这里将发挥 [@BuilderParam] 装饰器作用,先定义基础页面

组件中定义了 @Prop netLoad:boolean 变量来控制是否展示加载动画

@Component
export struct BasePage {
  @Prop netLoad: boolean

  //指向一个组件  
  @BuilderParam aB0: () => {}

  build(){
     Stack(){
       
       //为组件占位
       this.aB0()

       if (this.netLoad) {
         LoadingProgress()
           .width(px2vp(150))
           .height(px2vp(150))
           .color(Color.Blue)
       }

     }.hitTestBehavior(HitTestMode.None)
  }

}

主页面布局代码

import { BasePage } from './BasePage'

@Entry
@Component
struct NetIndex {
  @State netLoad: number = 0
  @State msg: string = ''

  build() {
      Stack(){
        BasePage({netLoad: this.netLoad != 0}) {
          Column( {space: 20} ){

            Row({space: 20}){
              Text('WeiBo').fontColor(Color.Black)
              Text('UniDemo').fontColor(Color.Black)
              Text('HuaWei').fontColor(Color.Black)
            }

            Row({space: 20}){
              Text('WeiBo' + this.weiboIndex)
              Text('UniDemo' + this.uniIndex)
              Text('HuaWei' + this.huaweiIndex)
            }

            Button('开始网络请求 - 异步').fontSize(20).onClick( () => {
                ...
            })

            Button('开始网络请求 - 同步').fontSize(20).onClick( () => {
                ...
            })

            Button('开始网络请求-自定义方法装饰器').fontSize(20).onClick( () => {
              ...
            })

            Scroll() {
              Text(this.msg).width('100%')
            }
            .scrollable(ScrollDirection.Vertical)
          }
          .width('100%')
          .height('100%')
          .padding({top: px2vp(120)})
        }

      }
  }

}

简单装封装网络请求

函数传参,直接调用封装方法

WeiBo为数据结构体,暂时不用关心,后续会贴出完整代码,这里仅仅是演示网络请求用法

//引用封装好的HNet网络工具类
import HNet from './util/HNet'

@State msg: string = ''
    
getWeiBoData(){
   HNet.get<WeiBo>({
  url: 'https://m.weibo.cn/api/feed/trendtop?containerid=102803_ctg1_4188_-_ctg1_4188',
}).then( (r) => {

  this.msg = ''

  if(r.code == 0 && r.result){
    r.result.data.statuses.forEach((value: WeiBoItem) => {
      this.msg = this.msg.concat(value.created_at + ' ' + value.id + '\n')
    })
  } else {
    this.msg = r.code + ' ' + r.msg
  }
  console.log('顺序-weibo-' + (new Date().getTime() - starTime))

  this.netLoad--

})    
   
}

自定义方法装饰器,完成传参调用

网络请求样例

NetController.getWeiBo<WeiBo>().then( r => {
   ......
})   

按照业务定义传参

import { Get, NetResponse } from './util/HNet'

export default class BizNetController {

  @Get('https://m.weibo.cn/api/feed/trendtop?containerid=102803_ctg1_4188_-_ctg1_4188')
  static getWeiBo<WeiBo>(): Promise<NetResponse<WeiBo>>{ return }

}

封装的网络请求代码

import http from '@ohos.net.http';

//自定义网络请求参数对象    
class NetParams{
  url: string
  extraData?: JSON
}

//自定义数据公共结构体    
export class NetResponse<T> {
  result: T
  code: number
  msg: string
}

//网络封装工具类    
class HNet {

  //POST 请求方法  
  static post<T>(options: NetParams): Promise<NetResponse<T>>{
    return this.request(options, http.RequestMethod.POST)
  }

  //GET 请求方法  
  static get<T>(options: NetParams): Promise<NetResponse<T>>{
    return this.request(options, http.RequestMethod.GET)
  }

    
  private static request<T>(options: NetParams, method: http.RequestMethod): Promise<NetResponse<T>>{

    let r = http.createHttp()

    return r.request(options.url, {
      method: method,
      extraData: options.extraData != null ? JSON.stringify(options.extraData) : null
    }).then( (response: http.HttpResponse) => {

      let netResponse = new NetResponse<T>()

      let dataType = typeof response.result

      if(dataType === 'string'){
         console.log('结果为字符串类型')
      }

      if(response.responseCode == 200){
        netResponse.code = 0
        netResponse.msg = 'success'
        netResponse.result = JSON.parse(response.result as string)

      } else {
        //出错
        netResponse.code = -1
        netResponse.msg = 'error'

      }

      return netResponse

    }).catch( reject => {
      console.log('结果发生错误')

      let netResponse = new NetResponse<T>()
      netResponse.code = reject.code
      netResponse.msg  = reject.message
      return netResponse

    }).finally( () => {
       //网络请求完成后,需要进行销毁
       r.destroy()
    })

  }

}

export default HNet 
    
//用于装饰器传参
export function Get(targetUrl: string) : MethodDecorator {

  return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
        //替换方法
        descriptor.value = () => {
           let options = new NetParams()
           options.url = targetUrl
            return HNet.get(options)
        }
  }

}

完整代码

代码结构

net/BasePage.ets

net/NetRequest.ets

net/util/HNet.ts

net/viewmodel/WeiBoModel.ts

net/BizNetController.ets

详细代码

@Component
export struct BasePage {
  @Prop netLoad: boolean

  @BuilderParam aB0: () => {}

  build(){
     Stack(){

       this.aB0()

       if (this.netLoad) {
         LoadingProgress()
           .width(px2vp(150))
           .height(px2vp(150))
           .color(Color.Blue)
       }

     }.hitTestBehavior(HitTestMode.None)
  }

}   
import HNet from './util/HNet'
import NetController from './BizNetController'
import { WeiBo, WeiBoItem } from './viewmodel/WeiBoModel'
import { BasePage } from './BasePage'

@Entry
@Component
struct NetIndex {
  @State netLoad: number = 0
  @State msg: string = ''

  @State weiboColor: Color = Color.Black
  @State uniColor: Color = Color.Black
  @State huaweiColor: Color = Color.Black

  @State weiboIndex: number = 1
  @State uniIndex: number = 2
  @State huaweiIndex: number = 3

  private  TEST_Target_URL: string[] = [
    'https://m.weibo.cn/api/feed/trendtop?containerid=102803_ctg1_4188_-_ctg1_4188',
    'https://unidemo.dcloud.net.cn/api/news',
    'https://developer.huawei.com/config/cn/head.json',
  ]

  build() {
      Stack(){
        BasePage({netLoad: this.netLoad != 0}) {
          Column( {space: 20} ){

            Row({space: 20}){
              Text('WeiBo').fontColor(Color.Black)
              Text('UniDemo').fontColor(Color.Black)
              Text('HuaWei').fontColor(Color.Black)
            }

            Row({space: 20}){
              Text('WeiBo' + this.weiboIndex).fontColor(this.weiboColor)
              Text('UniDemo' + this.uniIndex).fontColor(this.uniColor)
              Text('HuaWei' + this.huaweiIndex).fontColor(this.huaweiColor)
            }

            Button('开始网络请求 - 异步').fontSize(20).onClick( () => {
                this.weiboColor = Color.Black
                this.uniColor = Color.Black
                this.huaweiColor = Color.Black
                this.weiboIndex = 1
                this.uniIndex = 2
                this.huaweiIndex = 3
                this.asyncGetData()
            })

            Button('开始网络请求 - 同步').fontSize(20).onClick( () => {
                this.weiboColor = Color.Black
                this.uniColor = Color.Black
                this.huaweiColor = Color.Black

                this.weiboIndex = 1
                this.uniIndex = 2
                this.huaweiIndex = 3
                this.syncGetData()
            })

            Button('开始网络请求-自定义方法装饰器').fontSize(20).onClick( () => {
              this.getWeiBoListByController()
            })

            Scroll() {
              Text(this.msg).width('100%')
            }
            .scrollable(ScrollDirection.Vertical)
          }
          .width('100%')
          .height('100%')
          .padding({top: px2vp(120)})
        }

      }
  }

  asyncGetData(){

    this.netLoad = 3;

    this.TEST_Target_URL.forEach( (value) => {

      HNet.get({
        url: value,
      }).then( (r) => {

        this.msg = JSON.stringify(r)

        if(value.indexOf('weibo') != -1){
          this.weiboColor = Color.Green
          this.weiboIndex = 3 - this.netLoad + 1
        } else if(value.indexOf('unidemo') != -1){
          this.uniColor = Color.Green
          this.uniIndex = 3 - this.netLoad + 1
        } else if(value.indexOf('huawei') != -1){
          this.huaweiColor = Color.Green
          this.huaweiIndex = 3 - this.netLoad + 1
        }

        this.netLoad--

      })
    })

  }

  async syncGetData() {

    let starTime
    let url
    this.netLoad = 3;

    starTime = new Date().getTime()
    url = this.TEST_Target_URL[0]

    starTime = new Date().getTime()
    if(url.indexOf('weibo') != -1){
      console.log('顺序-请求-weibo')
    } else if(url.indexOf('unidemo') != -1){
      console.log('顺序-请求-unidemo')
    } else if(url.indexOf('huawei') != -1){
      console.log('顺序-请求-huawei')
    }

    await HNet.get<WeiBo>({
      url: url,
    }).then( (r) => {

      this.msg = ''

      if(r.code == 0 && r.result){
        r.result.data.statuses.forEach((value: WeiBoItem) => {
          this.msg = this.msg.concat(value.created_at + ' ' + value.id + '\n')
        })
      } else {
        this.msg = r.code + ' ' + r.msg
      }

      if(url.indexOf('weibo') != -1){
        this.weiboColor = Color.Green
        this.weiboIndex = 3 - this.netLoad + 1
        console.log('顺序-返回-weibo-' + (new Date().getTime() - starTime))
      } else if(url.indexOf('unidemo') != -1){
        this.uniColor = Color.Green
        this.uniIndex = 3 - this.netLoad + 1
        console.log('顺序-返回-unidemo-' + (new Date().getTime() - starTime))
      } else if(url.indexOf('huawei') != -1){
        this.huaweiColor = Color.Green
        this.huaweiIndex = 3 - this.netLoad + 1
        console.log('顺序-返回-huawei-' + (new Date().getTime() - starTime))
      }

      this.netLoad--

    })

    starTime = new Date().getTime()
    url = this.TEST_Target_URL[1]

    starTime = new Date().getTime()
    if(url.indexOf('weibo') != -1){
      console.log('顺序-请求-weibo')
    } else if(url.indexOf('unidemo') != -1){
      console.log('顺序-请求-unidemo')
    } else if(url.indexOf('huawei') != -1){
      console.log('顺序-请求-huawei')
    }

    await HNet.get({
      url: url,
    }).then( (r) => {

      this.msg = JSON.stringify(r)

      if(url.indexOf('weibo') != -1){
        this.weiboColor = Color.Green
        this.weiboIndex = 3 - this.netLoad + 1
        console.log('顺序-返回-weibo-' + (new Date().getTime() - starTime))
      } else if(url.indexOf('unidemo') != -1){
        this.uniColor = Color.Green
        this.uniIndex = 3 - this.netLoad + 1
        console.log('顺序-返回-unidemo-' + (new Date().getTime() - starTime))
      } else if(url.indexOf('huawei') != -1){
        this.huaweiColor = Color.Green
        this.huaweiIndex = 3 - this.netLoad + 1
        console.log('顺序-返回-huawei-' + (new Date().getTime() - starTime))
      }

      this.netLoad--

    })

    starTime = new Date().getTime()
    url = this.TEST_Target_URL[2]

    starTime = new Date().getTime()
    if(url.indexOf('weibo') != -1){
      console.log('顺序-请求-weibo')
    } else if(url.indexOf('unidemo') != -1){
      console.log('顺序-请求-unidemo')
    } else if(url.indexOf('huawei') != -1){
      console.log('顺序-请求-huawei')
    }

    await HNet.get({
      url: url,
    }).then( (r) => {

      this.msg = JSON.stringify(r)

      if(url.indexOf('weibo') != -1){
        this.weiboColor = Color.Green
        this.weiboIndex = 3 - this.netLoad + 1
        console.log('顺序-返回-weibo-' + (new Date().getTime() - starTime))
      } else if(url.indexOf('unidemo') != -1){
        this.uniColor = Color.Green
        this.uniIndex = 3 - this.netLoad + 1
        console.log('顺序-返回-unidemo-' + (new Date().getTime() - starTime))
      } else if(url.indexOf('huawei') != -1){
        this.huaweiColor = Color.Green
        this.huaweiIndex = 3 - this.netLoad + 1
        console.log('顺序-返回-huawei-' + (new Date().getTime() - starTime))
      }

      this.netLoad--

    })

  }

  getHuaWeiSomeDataByNet(){

    this.netLoad = 1

    let starTime = new Date().getTime()

    console.log('顺序-huawei-请求' + starTime)

    HNet.get({
      url: 'https://developer.huawei.com/config/cn/head.json',
    }).then( (r) => {

      this.msg = JSON.stringify(r, null, '\t')

      this.netLoad--

      console.log('顺序-huawei-' + (new Date().getTime() - starTime))

    })

  }

  getWeiBoListByHNet(){

    this.netLoad = 1

    let starTime = new Date().getTime()

    console.log('顺序-weibo-请求' + starTime)

    HNet.get<WeiBo>({
      url: 'https://m.weibo.cn/api/feed/trendtop?containerid=102803_ctg1_4188_-_ctg1_4188',
    }).then( (r) => {

      this.msg = ''

      if(r.code == 0 && r.result){
        r.result.data.statuses.forEach((value: WeiBoItem) => {
          this.msg = this.msg.concat(value.created_at + ' ' + value.id + '\n')
        })
      } else {
        this.msg = r.code + ' ' + r.msg
      }
      console.log('顺序-weibo-' + (new Date().getTime() - starTime))

      this.netLoad--

    })
  }

  getWeiBoListByController(){

    this.netLoad = 1

    NetController.getWeiBo<WeiBo>().then( r => {

      this.msg = ''

      if(r.code == 0 && r.result){
        r.result.data.statuses.forEach((value: WeiBoItem) => {
          this.msg = this.msg.concat(value.created_at + ' ' + value.id + '\n' + value.source + '\n')
        })
      } else {
        this.msg = r.code + ' ' + r.msg
      }

      this.netLoad--

    })
  }

}    

import { Get, NetResponse } from './util/HNet'

export default class BizNetController {

  @Get('https://m.weibo.cn/api/feed/trendtop?containerid=102803_ctg1_4188_-_ctg1_4188')
  static getWeiBo<WeiBo>(): Promise<NetResponse<WeiBo>>{ return }

}    

import http from '@ohos.net.http';

class NetParams{
  url: string
  extraData?: JSON
}

export class NetResponse<T> {
  result: T
  code: number
  msg: string
}

class HNet {

  static post<T>(options: NetParams): Promise<NetResponse<T>>{
    return this.request(options, http.RequestMethod.POST)
  }

  static get<T>(options: NetParams): Promise<NetResponse<T>>{
    return this.request(options, http.RequestMethod.GET)
  }

  private static request<T>(options: NetParams, method: http.RequestMethod): Promise<NetResponse<T>>{

    let r = http.createHttp()

    return r.request(options.url, {
      method: method,
      extraData: options.extraData != null ? JSON.stringify(options.extraData) : null
    }).then( (response: http.HttpResponse) => {

      let netResponse = new NetResponse<T>()

      let dataType = typeof response.result

      if(dataType === 'string'){
         console.log('结果为字符串类型')
      }

      if(response.responseCode == 200){
        netResponse.code = 0
        netResponse.msg = 'success'
        netResponse.result = JSON.parse(response.result as string)

      } else {
        //出错
        netResponse.code = -1
        netResponse.msg = 'error'

      }

      return netResponse

    }).catch( reject => {
      console.log('结果发生错误')

      let netResponse = new NetResponse<T>()
      netResponse.code = reject.code
      netResponse.msg  = reject.message
      return netResponse

    }).finally( () => {
       r.destroy()
    })

  }

}

export default HNet

export function Get(targetUrl: string) : MethodDecorator {

  return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
        //替换方法
        descriptor.value = () => {
           let options = new NetParams()
           options.url = targetUrl
            return HNet.get(options)
        }
  }

}
    

export class WeiBo{
  ok: number
  http_code: number
  data: WeiBoDataObj
}

export class WeiBoDataObj{
  total_number: number
  interval: number
  remind_text: string
  page: number
  statuses: Array<WeiBoItem>
}

export class WeiBoItem{
  created_at: string
  id: string
  source: string
  textLength: number
}

最后呢,很多开发朋友不知道需要学习那些鸿蒙技术?鸿蒙开发岗位需要掌握那些核心技术点?为此鸿蒙的开发学习必须要系统性的进行。

而网上有关鸿蒙的开发资料非常的少,假如你想学好鸿蒙的应用开发与系统底层开发。你可以参考这份资料,少走很多弯路,节省没必要的麻烦。由两位前阿里高级研发工程师联合打造《鸿蒙NEXT星河版OpenHarmony开发文档》里面内容包含了(ArkTS、ArkUI开发组件、Stage模型、多端部署、分布式应用开发、音频、视频、WebGL、OpenHarmony多媒体技术、Napi组件、OpenHarmony内核、Harmony南向开发、鸿蒙项目实战等等)鸿蒙(Harmony NEXT)技术知识点

如果你是一名Android、Java、前端等等开发人员,想要转入鸿蒙方向发展。可以直接领取这份资料辅助你的学习。下面是鸿蒙开发的学习路线图。

高清完整版请点击→《鸿蒙NEXT星河版开发学习文档》

针对鸿蒙成长路线打造的鸿蒙学习文档。话不多说,我们直接看详细资料鸿蒙(OpenHarmony )学习手册(共计1236页)与鸿蒙(OpenHarmony )开发入门教学视频,帮助大家在技术的道路上更进一步。

《鸿蒙 (OpenHarmony)开发学习视频》

图片

《鸿蒙生态应用开发V2.0白皮书》

图片

《鸿蒙 (OpenHarmony)开发基础到实战手册》

获取这份鸿蒙星河版学习资料,请点击→《鸿蒙NEXT星河版开发学习文档》

OpenHarmony北向、南向开发环境搭建

图片

《鸿蒙开发基础》

  1. ArkTS语言

  2. 安装DevEco Studio

  3. 运用你的第一个ArkTS应用

  4. ArkUI声明式UI开发

  5. .……

图片

《鸿蒙开发进阶》

  1. Stage模型入门

  2. 网络管理

  3. 数据管理

  4. 电话服务

  5. 分布式应用开发

  6. 通知与窗口管理

  7. 多媒体技术

  8. 安全技能

  9. 任务管理

  10. WebGL

  11. 国际化开发

  12. 应用测试

  13. DFX面向未来设计

  14. 鸿蒙系统移植和裁剪定制

  15. ……

图片

《鸿蒙开发实战》

  1. ArkTS实践

  2. UIAbility应用

  3. 网络案例

  4. ……

图片

 获取这份鸿蒙星河版学习资料,请点击→《鸿蒙NEXT星河版开发学习文档》

总结

鸿蒙—作为国家主力推送的国产操作系统。部分的高校已经取消了安卓课程,从而开设鸿蒙课程;企业纷纷跟进启动了鸿蒙研发

并且鸿蒙是完全具备无与伦比的机遇和潜力的;预计到年底将有 5,000 款的应用完成原生鸿蒙开发,未来将会支持 50 万款的应用那么这么多的应用需要开发,也就意味着需要有更多的鸿蒙人才鸿蒙开发工程师也将会迎来爆发式的增长,学习鸿蒙势在必行!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1554950.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

同元软控专业模型库系列——液压气动篇

01 引言 近年来&#xff0c;数字液压技术在工业领域的应用逐渐推广&#xff0c;为提升生产效率、降低能源消耗、实现智能化制造提供了新的可能性。数字液压技术的应用已经覆盖了工程机械、航空航天、能源设备等众多领域&#xff0c;具有巨大的发展潜力。 行业技术的发展融合在…

机器人码垛机:智能仓储系统的重要组成部分

随着科技的飞速进步&#xff0c;机器人技术已经渗透到了许多行业领域&#xff0c;其中&#xff0c;仓储业尤为显著。机器人码垛机作为智能仓储系统的重要组成部分&#xff0c;不仅提高了码垛效率&#xff0c;还降低了人工成本和安全风险。然而&#xff0c;在其广泛应用的同时&a…

C# OpenCvSharp-HoughCircles(霍夫圆检测) 简单计数

目录 效果 项目 代码 下载 效果 项目 代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using OpenCvSharp; using O…

pycharm复习

1.字面量 2.注释&#xff1a; 单行注释# 多行注释" " " " " " 3.变量&#xff1a; 变量名 变量值 print&#xff1a;输出多个结果&#xff0c;用逗号隔开 4.数据类型&#xff1a; string字符串int整数float浮点数 t…

WebSocket 详解-小案例展示

简介&#xff1a;Websocket是一种用于H5浏览器的实时通讯协议&#xff0c;可以做到数据的实时推送&#xff0c;可适用于广泛的工作环境&#xff0c;例如客服系统、物联网数据传输系统&#xff0c;该测试工具可用于websocket开发初期的测试工作。 文章末尾有此案例的完整源代码。…

Arcgis中使用NDVI阈值法提取农田shape

首先有一幅NDVI影像TIFF&#xff0c;对其查看农田上的NDVI范围&#xff0c;大概是0.1以上&#xff0c;因为是12月份&#xff0c;小麦播种完1-2个月&#xff0c;此时NDVI并不是很高&#xff0c;但是树林基本叶子掉落了&#xff0c;所以比较好提取农田。 打开地图代数-栅格计算器…

【漏洞分析】浅析android手游lua脚本的加密与解密(一)

主要用到的工具和环境&#xff1a; 1 win7系统一枚 2 quick-cocos2d-x的开发环境&#xff08;弄一个开发环境方便学习&#xff0c;而且大部分lua手游都是用的cocos2d-x框架&#xff0c;还有一个好处&#xff0c;可以查看源码关键函数中的特征字符串&#xff0c;然后在IDA定位到…

选择华为HCIE培训机构有哪些注意事项

选择软件培训机构注意四点事项1、口碑&#xff1a;学员和社会人士对该机构的评价怎样&#xff1f; 口碑对于一个机构是十分重要的&#xff0c;这也是考量一个机构好不好的重要标准&#xff0c;包括社会评价和学员的评价和感言。誉天作为华为首批授权培训中心&#xff0c;一直致…

【计算机考研】数学难,到底难在哪里?看这一篇深度分析

数一和数二的难度系数都不在一个重量级&#xff01; 数一这货&#xff0c;容量真不是数二能比的&#xff01;除了高数、线代这些常规操作&#xff0c;还要啃概率论与数理统计这本大厚书&#xff0c;简直是让人头大&#xff01; 考研数学嘛&#xff0c;大家都知道&#xff0c;…

【详细讲解Android Debug Bridge各种命令及用法的文章】

&#x1f525;博主&#xff1a;程序员不想YY啊&#x1f525; &#x1f4ab;CSDN优质创作者&#xff0c;CSDN实力新星&#xff0c;CSDN博客专家&#x1f4ab; &#x1f917;点赞&#x1f388;收藏⭐再看&#x1f4ab;养成习惯 &#x1f308;希望本文对您有所裨益&#xff0c;如有…

微服务demo(四)nacosfeigngateway

一、gateway使用&#xff1a; 1、集成方法 1.1、pom依赖&#xff1a; 建议&#xff1a;gateway模块的pom不要去继承父工程的pom&#xff0c;父工程的pom依赖太多&#xff0c;极大可能会导致运行报错&#xff0c;新建gateway子工程后&#xff0c;pom父类就采用默认的spring-b…

算法——动态规划:01背包

原始01背包见下面这篇文章&#xff1a;http://t.csdnimg.cn/a1kCL 01背包的变种&#xff1a;. - 力扣&#xff08;LeetCode&#xff09; 给你一个 只包含正整数 的 非空 数组 nums 。请你判断是否可以将这个数组分割成两个子集&#xff0c;使得两个子集的元素和相等。 简化一…

HTML input 实现回车切换到下一个输入框功能

前言 遇到需求&#xff0c;在客户填写单子时&#xff0c;有多个输入框&#xff0c;为了省事&#xff0c;不需要频繁移动光标填写。 实现效果 实现方式一 HTML <input type"text" name"serialNumber1" onkeydown"cursor(this);"/><in…

Elasticsearch 开放 inference API 增加了对 Cohere Embeddings 的支持

作者&#xff1a;来自 Elastic Serena Chou, Jonathan Buttner, Dave Kyle 我们很高兴地宣布 Elasticsearch 现在支持 Cohere 嵌入&#xff01; 发布此功能是与 Cohere 团队合作的一次伟大旅程&#xff0c;未来还会有更多合作。 Cohere 是生成式 AI 领域令人兴奋的创新者&…

打PTA (15分)(JAVA)

目录 题目描述 输入格式&#xff1a; 输出格式&#xff1a; 输入样例&#xff1a; 输出样例&#xff1a; 题解 题目描述 传说这是集美大学的学生对话。本题要求你做一个简单的自动问答机&#xff0c;对任何一个问句&#xff0c;只要其中包含 PTA 就回答 Yes!&#xff0c;其…

大模型重塑电商,淘宝、百度、京东讲出新故事

配图来自Canva可画 随着AI技术日渐成熟&#xff0c;大模型在各个领域的应用也越来越深入&#xff0c;国内互联网行业也随之进入了大模型竞赛的后半场&#xff0c;开始从“百模大战”转向了实际应用。大模型从通用到细分垂直领域的跨越&#xff0c;也让更多行业迎来了新的商机。…

Pytorch从零开始实战22

Pytorch从零开始实战——CycleGAN实战 本系列来源于365天深度学习训练营 原作者K同学 内容介绍 CycleGAN是一种无监督图像到图像转换模型&#xff0c;它的一个重要应用领域是域迁移&#xff0c;比如可以把一张普通的风景照变化成梵高化作&#xff0c;或者将游戏画面变化成真…

python可视化:tqdm进度条控制台输出模块

前言 在处理大量数据或执行耗时操作时&#xff0c;了解代码执行的进度是至关重要的。在Python中&#xff0c;通过使用进度条可以有效地实现对代码执行进度的可视化展示。 tqdm 是一个快速、可扩展的Python进度条库&#xff0c;能够实时显示代码执行的进度。并且它提供了简洁的A…

环境温度对测量平板有什么影响

环境温度可以对测量平板有影响。温度变化可以导致平板的尺寸发生变化。根据热膨胀原理&#xff0c;当环境温度升高时&#xff0c;平板的尺寸会扩大&#xff1b;当环境温度降低时&#xff0c;平板的尺寸会缩小。这种尺寸变化可能会导致测量结果的误差。因此&#xff0c;在测量平…

9、jenkins微服务持续集成(一)

文章目录 一、流程说明二、源码概述三、本地部署3.1 SpringCloud微服务部署本地运行微服务本地部署微服务3.2 静态Web前端部署四、Docker快速入门一、流程说明 Jenkins+Docker+SpringCloud持续集成流程说明 大致流程说明: 开发人员每天把代码提交到Gitlab代码仓库Jenkins从G…