Using webservices in android

2019-09-08 15:47发布

问题:

I have the following site http://www.freewebservicesx.com/GoldSpotPrice.aspx which provides a webservice api. As i am extremely new to soap and rest i have absolutely no clue about how to call this service and use it in android. Could someone please tell me how to do it.

回答1:

You can make HTTP requests using either HttpURLConnection or HttpClient. Example of using HttpClient for a RESTful web service:

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
}

Otherwise, if you're working with a SOAP web service, I would recommend using ksoap2



回答2:

Use the following url to refer:::

LINK1

LINK2

LINK3

Use this LINK it has a sample the suits your requirement.

also LINK