android networking - How to make a GET Request using okhttp -


i new android development , know how perform request using okhttp. have referred http://square.github.io/okhttp/, have examples of post request. have tried -

        okhttpclientlogin = new okhttpclient();         requestbodylogin = new formbody.builder()                 .addencoded("name", name_input) // params                 .addencoded("keys", keys_input) //params                 .build();          requestlogin = new request.builder()                 .addheader("authorization", token_type + " " +access_token)                 .url(login_url)                 .get()                 .build(); 

and got error :

{"status":{"status":206,"msg":"no record found"},"user":null}

i know why error coming, because params have not been entered. tried passing requestbodylogin inside .get() it's not allowing.

since okhttp 2.4, there's function addqueryparameter. can either use httpurl, string or java.net.url url. basically, create new httpurl.builder() , use function addqueryparameter.

example taken javadocs:

httpurl url = new httpurl.builder()        .scheme("https")        .host("www.google.com")        .addpathsegment("search")        .addqueryparameter("q", "polar bears")        .build(); 

http://square.github.io/okhttp/3.x/okhttp/okhttp3/httpurl.html

http://square.github.io/okhttp/2.x/okhttp/com/squareup/okhttp/httpurl.builder.html#addqueryparameter-java.lang.string-java.lang.string-


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -