【问题标题】:Using webservices in android在安卓中使用网络服务
【发布时间】:2012-04-07 03:40:46
【问题描述】:

我有以下站点 http://www.freewebservicesx.com/GoldSpotPrice.aspx,它提供了一个 webservice api。由于我对肥皂和休息非常陌生,我完全不知道如何调用此服务并在 android 中使用它。谁能告诉我怎么做。

【问题讨论】:

    标签: android rest soap


    【解决方案1】:

    您可以使用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

    【讨论】:

    【解决方案2】:

    使用以下网址引用:::

    Using ksoap2 for android, and parsing output data...

    ksoap2-android - HowToUse.wiki.....

    ksoap2-android

    使用这个LINK 它有一个适合您要求的样品。

    还有LINK

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-08
    • 2013-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多