我需要从网址获取所有标头。这样做我使用以下代码
try {
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet("http://onlineservice.banglalinkgsm.com/Construction.htm");
HttpResponse response = client.execute(request);
Header[] headers = response.getAllHeaders();
for (Header header : headers) {
Result =Result +"Key : " + header.getName()
+ " ,Value : " + header.getValue();
}
catch (Exception e) { }
但是当我运行应用程序时它会崩溃。我无法弄清楚我犯了哪些错误。请帮我。 目前我正在添加httpclient-4.3库。我也测试了httpclient-4.3.2库。
这是我的logcat
02-09 14:27:10.527: E/dalvikvm(7780): Could not find class 'org.apache.http.impl.conn.PoolingHttpClientConnectionManager', referenced from method org.apache.http.impl.client.HttpClientBuilder.build
02-09 14:27:10.554: E/AndroidRuntime(7780): FATAL EXCEPTION: main
02-09 14:27:10.554: E/AndroidRuntime(7780): java.lang.NoClassDefFoundError: org.apache.http.impl.conn.PoolingHttpClientConnectionManager
02-09 14:27:10.554: E/AndroidRuntime(7780): at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:460)
02-09 14:27:10.554: E/AndroidRuntime(7780): at com.example.headerread.MainActivity$1.onClick(MainActivity.java:93)
02-09 14:27:10.554: E/AndroidRuntime(7780): at android.view.View.performClick(View.java:4212)
02-09 14:27:10.554: E/AndroidRuntime(7780): at android.view.View$PerformClick.run(View.java:17476)
02-09 14:27:10.554: E/AndroidRuntime(7780): at android.os.Handler.handleCallback(Handler.java:800)
02-09 14:27:10.554: E/AndroidRuntime(7780): at android.os.Handler.dispatchMessage(Handler.java:100)
02-09 14:27:10.554: E/AndroidRuntime(7780): at android.os.Looper.loop(Looper.java:194)
02-09 14:27:10.554: E/AndroidRuntime(7780): at android.app.ActivityThread.main(ActivityThread.java:5371)
02-09 14:27:10.554: E/AndroidRuntime(7780): at java.lang.reflect.Method.invokeNative(Native Method)
02-09 14:27:10.554: E/AndroidRuntime(7780): at java.lang.reflect.Method.invoke(Method.java:525)
02-09 14:27:10.554: E/AndroidRuntime(7780): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
02-09 14:27:10.554: E/AndroidRuntime(7780): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
02-09 14:27:10.554: E/AndroidRuntime(7780): at dalvik.system.NativeStart.main(Native Method)
02-09 14:27:10.602: E/AppErrorDialog(504): Failed to get ILowStorageHandle instance
答案 0 :(得分:0)
您似乎没有声明soapResult
变量并将Result
与soapResult
混淆。
尝试替换:
for (Header header : headers) {
Result =soapResult +"Key : " + header.getName()
+ " ,Value : " + header.getValue();
通过
String soapResult;
for (Header header : headers) {
soapResult =soapResult +"Key : " + header.getName()
+ " ,Value : " + header.getValue();
答案 1 :(得分:0)
在“订购和导出”选项卡下检查库文件...通过右键单击转到项目属性 - >然后Java Build Path ...按照上面的图片......