How to send multiple strings per url in Android studio?

Asked

Viewed 128 times

0

I have data to send to a web server, the server receives the strings following this pattern:

http://teste.com/{id}/{latitude}/{longitude}

How do I send this data occupying these spaces at once by Android studio?

2 answers

0

I highly recommend using the retrofit to consume Apis

interface TesteService{
    @GET("{id}/{latitude}/{longitude}"
    Call<Objeto> getObject(@Path("id") String id,
                           @Path("latitude") String latitude,
                           @Path("longitude") String longitude);
}

public class TesteRetrofit{
    Retrofit retrofit = new Retrofit.Builder()
        .baseUrl("http://teste.com/")
        .build();
    TesteService tService = retrofit.create(TesteService.class);

    public Objeto pegarObjeto(){
     return tService.getObject("123","20°34'07.2\"S","43°48'44.6\"W").execute().body();
    }
}

This is a basic example of code, I suggest a read on documentation to learn more.

That code will make the exception I/O on UIThread run in the main thread of Android

0

Simple:

String url = "http://teste.com/pagina?id=" + id + "&latitude=" + latitude + "&longitude=" + longitude;

After the server side:

$id = $_GET['id'];
$latitude = $_GET['latitude'];
$longitude = $_GET['longitude'];

This page from android Developer teaches to do something similar using Volley, but I would do it using POST instead of GET for security reasons, since it is sent by url may have your data changed, more information page w3schools.com

Browser other questions tagged

You are not signed in. Login or sign up in order to post.