资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

android开发中使用okhttp上传文件到服务器-创新互联

开发android手机客户端,常常会需要上传文件到服务器,比如:你手机里的照片。

为嵩县等地区用户提供了全套网页设计制作服务,及嵩县网站建设行业解决方案。主营业务为成都做网站、成都网站制作、嵩县网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

使用okhttp会是一个很好的选择。它使用很简单,而且运行效率也很高。

首先,在 app/build.gradle 的 dependencies 增加 implementation 'com.squareup.okhttp3:okhttp:3.8.1' 可以参照如下代码

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
  compileSdkVersion 26
  defaultConfig {
    applicationId "com.cofox.mykt.myweather"
    minSdkVersion 19
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  }
  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
  sourceSets {
    main {
      res.srcDirs =
          [
              'src/main/res/layout/menufunction',
              'src/main/res'
          ]
    }
  }
}
dependencies {
  implementation fileTree(dir: 'libs', include: ['*.jar'])
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
  implementation 'com.android.support:appcompat-v7:26.1.0'  implementation 'com.android.support.constraint:constraint-layout:1.0.2'
  testImplementation 'junit:junit:4.12'  androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
  implementation 'org.jetbrains.anko:anko-sdk19:0.10.3'
  implementation 'org.jetbrains.anko:anko-support-v4:0.10.3'
  implementation 'org.jetbrains.anko:anko-appcompat-v7:0.10.3'
  implementation 'com.google.code.gson:gson:2.7'
implementation 'com.android.support:percent:26.1.0'
  implementation 'com.squareup.okhttp3:okhttp:3.8.1'
}

文章标题:android开发中使用okhttp上传文件到服务器-创新互联
URL网址:http://cdkjz.cn/article/pgjpd.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220