我试过httpClIEnt,httpCore和许多不同的版本.也可以从外部罐子和maven建议.
我最终得到了这个:
compile 'org.apache.httpcomponents:httpcore:4.4.1'compile 'org.apache.httpcomponents:httpclIEnt:4.3.5'
它仍然给我无法解析httpClIEnt并且无法解析httpPost等.
它不提供我导入类.
做http帖子的代码:
// Create a new httpClIEnt and Post header httpClIEnt httpclIEnt = new DefaulthttpClIEnt(); httpPost httppost = new httpPost("http://fdsgsfdgs); try { // Add your data List<nameValuePair> nameValuePairs = new ArrayList<>(2); nameValuePairs.add(new BasicnameValuePair("ID",null)); nameValuePairs.add(new BasicnameValuePair("name","TestFromAppSpell")); nameValuePairs.add(new BasicnameValuePair("damage","12345")); nameValuePairs.add(new BasicnameValuePair("heal","50")); nameValuePairs.add(new BasicnameValuePair("description","Testtestest")); nameValuePairs.add(new BasicnameValuePair("coordinates",coordinates)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute http Post Request httpResponse response = httpclIEnt.execute(httppost); System.out.println("http post done!"); } catch (ClIEntProtocolException e) { // Todo auto-generated catch block } catch (IOException e) { // Todo auto-generated catch block }
Gradle文件:
buildscript { repositorIEs { jcenter() } dependencIEs { classpath 'com.androID.tools.build:gradle:1.2.3' }}apply plugin: 'com.androID.application'repositorIEs { jcenter()}dependencIEs { compile 'com.androID.support:support-v4:23.0.0' compile 'com.androID.support:grIDlayout-v7:23.0.0' compile 'com.androID.support:cardvIEw-v7:23.0.0' compile 'org.apache.httpcomponents:httpcore:4.4.1' compile 'org.apache.httpcomponents:httpclIEnt:4.3.5'}dependencIEs { compile 'com.androID.support:appcompat-v7:+' compile filetree(dir: 'libs',include: ['*.jar'])}// The sample build uses multiple directorIEs to// keep boilerplate and common code separate from// the main sample code.List<String> dirs = [ 'main',// main sample code; look here for the interesting stuff. 'common',// components that are reused by multiple samples 'template'] // boilerplate code that is generated by the sample template processandroID { compileSdkVersion 23 buildToolsversion "23.0.0" defaultConfig { minSdkVersion 11 targetSdkVersion 23 } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } sourceSets { main { dirs.each { dir -> java.srcDirs "src/${dir}/java" res.srcDirs "src/${dir}/res" } } androIDTest.setRoot('tests') androIDTest.java.srcDirs = ['tests/src'] }}解决方法 SDK 23中不再支持httpClIEnt.您必须使用URLConnection或降级到SDK 22(编译’com.androID.support:appcompat-v7:22.2.0′)
如果您需要SDK 23,请将其添加到您的gradle:
androID { uselibrary 'org.apache.http.legacy'}总结
以上是内存溢出为你收集整理的android – 无法解析符号:’HttpClient’,即使在添加依赖项之后全部内容,希望文章能够帮你解决android – 无法解析符号:’HttpClient’,即使在添加依赖项之后所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)