如何访问一个网页内容(POST / GET)的Android应用程序? [英] How to access a web content (POST/GET) in an Android application?
问题描述
我的要求是非常相似这个问题。
基本上,我将有我的Android应用程序登录的活动,当用户输入数据并点击登录,我打我的网站,认证用户,得到的结果回来,引导用户进一步基于登录成功或不是。
下面是我的问题。
- 什么是执行上面的android的选择我吗?我怎样才能POST数据并取回我的活动结果?
- 如果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.
- what are the options for me to implement the above in android? How can I POST data and get results back in my Activity?
- 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)的Android应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!