如何使用Android执行URL?

3 java android

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

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

https://www.12voip.com/myaccount/sendsms.php?username=w?&password=x&from=y&to=z&text=some%20text
Run Code Online (Sandbox Code Playgroud)

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

谁能帮助我用android执行url?

maf*_*fro 9

安卓包含Apache的HTTP组件封装org.apache.http.在那里,您将找到使用参数调用URL所需的一切.

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

你需要做这样的事情:

  1. 创建一个HttpClient(HttpClient client = new DefaultHttpClient();)
  2. 创建URL(HttpGet req = new HttpGet("url-without-params");)的GET方法
  3. 向method(req.setParams(params);)添加参数
  4. 使用client(HttpResponse res = client.executeMethod(req);)执行方法
  5. 检查回复(res.getStatusLine().getStatusCode();)

祝好运!