Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android中的HTTP连接_Android_Http - Fatal编程技术网

Android中的HTTP连接

Android中的HTTP连接,android,http,Android,Http,如何创建Http连接以将网页内容检索到我的android?请发布此示例代码。其http客户端,获取示例,它可能会有所帮助 HttpClient client; HttpGet method; String url; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); url="enter your url here"

如何创建Http连接以将网页内容检索到我的android?请发布此示例代码。

其http客户端,获取示例,它可能会有所帮助

    HttpClient client;
    HttpGet method;
    String url;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    url="enter your url here";
    method = new HttpGet(url);
    try {
            client.execute(method);


        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
           setContentView(R.layout.main);
}
public void executeHttpGet() throws Exception {
    BufferedReader in = null;
    try {
        client = new DefaultHttpClient();
        HttpGet request = new HttpGet();
        request.setURI(new URI(url));
        HttpResponse response = client.execute(method);
        in = new BufferedReader
        (new InputStreamReader(response.getEntity().getContent()));
        StringBuffer sb = new StringBuffer("");
        String line = "";
        String NL = System.getProperty("line.separator");
        while ((line = in.readLine()) != null) {
            sb.append(line + NL);
        }
        in.close();
        String page = sb.toString();
        System.out.println(page);
        } finally {
        if (in != null) {
            try {
                in.close();
                } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

它在预览中访问XML数据,我尝试了这个示例。

我在手机中获取XML数据,因此如何在不使用XML标记的情况下转换为真实数据?我没有尝试在这里查找,我认为这对您有帮助。