简体   繁体   English

Android中的Apache Http客户端

[英]Apache Http Client in Android

I'm trying to get the whole html from a web page in Android. 我正在尝试从Android的网页中获取整个html。

In java console aplication I used to do like this: 在Java控制台应用程序中,我曾经这样做:

DefaultHttpClient httpclient = new DefaultHttpClient();
String busca = "kindle";        
HttpGet httpGet = new HttpGet("http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords="+busca);
try {
    ResponseHandler<String> manipulador = new BasicResponseHandler();
    String resposta = httpclient.execute(httpGet,manipulador);
    }

} finally {
    httpGet.releaseConnection();
}

I tried to do the same in my Android aplication but I didn't work! 我尝试在Android应用程序中执行相同的操作,但是没有工作!

This library works in Android? 这个程式库可以在Android上运作吗?

import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;

Is there in better way to get a page html code in a string on Android? 是否有更好的方法来在Android上的字符串中获取页面html代码?

Thks for the help! 谢谢你的帮助!

I did it with another URl and it worked :) 我用另一个URl做到了,它很有效:)

Maybe the HTML code of that page I was using as to big to save in a String or to show in a Text 也许我使用的那个页面的HTML代码很大,可以保存为字符串或显示为文本

You can have a loot at this : HttpClient 4.0.1 - how to release connection? 您可以通过以下方式获得战利品: HttpClient 4.0.1-如何释放连接?

HttpRequestBase.releaseConnection() is introduced in Version 4.2 在版本4.2中引入了HttpRequestBase.releaseConnection()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM