如何访问一个网页内容(POST / GET)的Andr​​oid应用程序? [英] How to access a web content (POST/GET) in an Android application?

查看:118
本文介绍了如何访问一个网页内容(POST / GET)的Andr​​oid应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是非常相似这个问题

基本上,我将有我的Andr​​oid应用程序登录的活动,当用户输入数据并点击登录,我打我的网站,认证用户,得到的结果回来,引导用户进一步基于登录成功或不是。

下面是我的问题。

  1. 什么是执行上面的android的选择我吗?我怎样才能POST数据并取回我的活动结果?
  2. 如果WebViews时,可以这样简单?
解决方案

您可以张贴到URI与的HttpClient

  URI URI = URI.create(http://whatever.com/thingie);
HttpPost后=新HttpPost(URI);
StringEntity ENT =新StringEntity(这是我的数据!);
post.setEntity(ENT);
HttpClient的HttpClient的=新DefaultHttpClient();
HTT presponse响应= httpClient.execute(要求);
 

所有你需要看的东西在包 org.apache.http.client 。有一个良好的数额进一步的例子在那里在互联网上帮助你。

My requirement is very much similar to this question.

Basically, I will be having a login Activity in my android app and when the user enters data and clicks login, I have to hit my website, authenticates users, get the result back and guide the user further based on login success or not.

Here are my questions.

  1. what are the options for me to implement the above in android? How can I POST data and get results back in my Activity?
  2. If WebViews are used, can this be simplified?

解决方案

You can POST to a URI with HttpClient:

URI uri = URI.create("http://whatever.com/thingie");
HttpPost post = new HttpPost(uri);
StringEntity ent = new StringEntity("Here is my data!");
post.setEntity(ent);
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);

All the stuff you need to look at is in the package org.apache.http.client. There is a good amount of further examples out there on the internet to help you.

这篇关于如何访问一个网页内容(POST / GET)的Andr​​oid应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆