【发布时间】:2012-04-07 03:40:46
【问题描述】:
我有以下站点 http://www.freewebservicesx.com/GoldSpotPrice.aspx,它提供了一个 webservice api。由于我对肥皂和休息非常陌生,我完全不知道如何调用此服务并在 android 中使用它。谁能告诉我怎么做。
【问题讨论】:
我有以下站点 http://www.freewebservicesx.com/GoldSpotPrice.aspx,它提供了一个 webservice api。由于我对肥皂和休息非常陌生,我完全不知道如何调用此服务并在 android 中使用它。谁能告诉我怎么做。
【问题讨论】:
您可以使用HttpURLConnection 或HttpClient 发出HTTP 请求。将HttpClient 用于 RESTful Web 服务的示例:
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://www.mywebsite.com/webservice");
HttpResponse response = httpClient.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
HttpEntity entity = response.getEntity();
ByteArrayOutputStream out = new ByteArrayOutputStream();
entity.writeTo(out);
out.close();
String responseStr = out.toString();
// process response
} else {
// handle bad response
}
否则,如果您使用的是 SOAP Web 服务,我建议您使用 ksoap2
【讨论】:
使用以下网址引用:::
Using ksoap2 for android, and parsing output data...
ksoap2-android - HowToUse.wiki.....
使用这个LINK 它有一个适合您要求的样品。
还有LINK
【讨论】: