Consume WebService PHP using Java / Android [closed]

0

I build following a friend's guidance a webservice using php (actually it's a web application that returns all requests made via post a string in json format).

First what I would like to know is if this what I did is actually a webservice ?

Second, what I wanted to do now was to consume this webservice using an application made with java , more precisely android .

I have no idea what to do to consume this webservice .

So I would expect you to explain to me what I need to do and to point out some tutorials on the internet or even provide a code for me to base.

Thank you for your cooperation!

    
asked by anonymous 06.06.2017 / 23:17

2 answers

1

In general terms, webservice is a function that can be accessed by another program using the web protocol (HTTP), that is, if your program returns an html that can be viewed by a human, this is not a webservice , however, if it is returning a JSON that will be consumed by another program, then yes we can say that it is a webservice

This is a brief definition and there is a more elaborate concept behind it.

To send http requests using Android, I use the Volley library, which is present in the official Android documentation that you can check out here .

A simple example of a request using the Volley:

// Criamos a fila de requisições
RequestQueue fila = Volley.newRequestQueue(this);
String endpoint = "https://api.punkapi.com/v2/beers";

// Criamos a request string a partir da URL
StringRequest stringRequest = new StringRequest(Request.Method.GET, endpoint, 
    new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            Log.d("Response", "is: "+ response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d("Response Error", "Erro na requisição!");
        }
    });
    // Adicionamos a requisição a fila de requisições
    fila.add(stringRequest);
    
07.06.2017 / 02:30
0

Basically, you will need to run calls via HTTP pro to the web address that is running the webservice application.

You can make calls to the webservice manually, using a tool like curL, postman, etc., to better understand how it works.

To do this in Java you can use a library that abstracts quite a bit of logic for you, such as link and implement it as needed your program.

    
07.06.2017 / 03:42