0

I have been trying to look for cURL requests for Android Studio, specifically for this type of request in particular:

curl -d "grant_type=client&client_id=123&client_secret=456" https://api.someapp.com/v2/oauth2/token

I have been looking for solutions around the site, but the only closest answer to exist is: CURL in android

This doesn't solve my issue of the -d command (the link solves for -u), as well as the need for customizable headers (link gives only :, rather than &).

Any help is appreciated!

Otter B
  • 43
  • 5

1 Answers1

0

Just figured it out, never mind guys!

POST with data:

try {
            HttpClient client = new DefaultHttpClient();
            String postURL = "https://api.someapp.com/v2/oauth2/token";
            HttpPost post = new HttpPost(postURL);
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("grant_type","client"));
            params.add(new BasicNameValuePair("client_id","123"));
            params.add(new BasicNameValuePair("client_secret","456"));
            UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8);
            post.setEntity(ent);
            HttpResponse responsePOST = client.execute(post);
            HttpEntity resEntity = responsePOST.getEntity();
            if (resEntity != null) {
                // Successful results
                Log.i("Results", EntityUtils.toString(resEntity));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
Otter B
  • 43
  • 5