HttpGet

首先要有架包:戳这儿下载

其次要有访问网络的权限:<uses-permissionandroid:name="android.permission.INTERNET"/>

代码:

try{
    HttpClient httpClient = new DefaultHttpClient();
    String url = "http://v.juhe.cn/weather/index";
    HttpGet httpGet = new HttpGet(url);
    HttpResponse httpResponse = httpClient.execute(httpGet);
    if(httpResponse.getStatusLine().getStatusCode()==200) {
        result = EntityUtils.toString(httpResponse.getEntity());
    }
}catch(Exception e){
    e.printStackTrace();
}

如果编译时出现下面的报错的话

Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2411Library UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72411Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42411Library UP-TO-DATE
:app:prepareComAndroidSupportSupportVectorDrawable2411Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareDebugAndroidTestDependencies
:app:compileDebugAndroidTestAidl UP-TO-DATE
:app:processDebugAndroidTestManifest UP-TO-DATE
:app:compileDebugAndroidTestRenderscript UP-TO-DATE
:app:generateDebugAndroidTestBuildConfig UP-TO-DATE
:app:generateDebugAndroidTestAssets UP-TO-DATE
:app:mergeDebugAndroidTestAssets UP-TO-DATE
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources UP-TO-DATE
:app:mergeDebugAndroidTestResources UP-TO-DATE
:app:processDebugAndroidTestResources UP-TO-DATE
:app:generateDebugAndroidTestSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:preDexDebug UP-TO-DATE
:app:dexDebug UP-TO-DATE
:app:validateDebugSigning
:app:packageDebug
Error:duplicate files during packaging of APK C:\Users\asus1\AndroidStudioProjects\HttpGet\app\build\outputs\apk\app-debug-unaligned.apk
Path in archive: META-INF/LICENSE
Origin 1: C:\Users\asus1\AndroidStudioProjects\HttpGet\app\libs\httpmime-4.5.2.jar
Origin 2: C:\Users\asus1\AndroidStudioProjects\HttpGet\app\libs\httpclient-win-4.5.2.jar
You can ignore those files in your build.gradle:
android {
 packagingOptions {
   exclude 'META-INF/LICENSE'
 }
}
Error:Execution failed for task ':app:packageDebug'.
> Duplicate files copied in APK META-INF/LICENSE
File 1: C:\Users\asus1\AndroidStudioProjects\HttpGet\app\libs\httpmime-4.5.2.jar
File 2: C:\Users\asus1\AndroidStudioProjects\HttpGet\app\libs\httpclient-win-4.5.2.jar
Information:BUILD FAILED
Information:Total time: 6.223 secs
Information:2 errors
Information:0 warnings
Information:See complete output in console

就在build.gradle里面加上

packagingOptions {
    exclude 'META-INF/LICENSE'
  }

再编译的时候如果还有同样的错误就再加,一直到没有为止吐舌头


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值