如何使用Android执行URL?

时间:2009-08-11 18:07:10

标签: java android

我正在申请通过betamax向VOIP提供商发送短信。

要发送短信我只需要执行网址

https://www.12voip.com/myaccount/sendsms.php?username=w​&password=x&from=y&to=z&text=some%20text

我的应用已经创建了网址,但我无法理解如何执行。我想我必须为此发出一个http请求。但我完全不明白。

任何人都可以帮我执行android的url吗?

2 个答案:

答案 0 :(得分:8)

Android包含org.apache.http包中的Apache Http Components。在那里,您将找到调用带参数的URL所需的一切。

在这里,您将找到客户端教程:http://hc.apache.org/httpcomponents-client/tutorial/html/

你需要做这样的事情:

  1. 创建HttpClient(HttpClient client = new DefaultHttpClient();
  2. 为网址(HttpGet req = new HttpGet("url-without-params");
  3. 创建GET方法
  4. 向方法(req.setParams(params);
  5. 添加参数
  6. 使用客户端(HttpResponse res = client.executeMethod(req);
  7. 执行方法
  8. 检查回复(res.getStatusLine().getStatusCode();
  9. 祝你好运!

答案 1 :(得分:0)

我不是100%确定你要做什么,但答案是使用Apache Http Client which is included in android

Here's the tutorial