I am new in android, I don't know how to add headers and value and get code.
I have a client id and client secret key. So i want to get gc code from the "http:.....grandcode.json", how to add headers and value .
In Postman.successfully return code but could in android code.
In above picture; I have client id and client secret key. and request url grant_code.json and return on code. I want use this code but could not know to how to add headers value id and secret key.
Thank you in advance.
Here, simple answer to add headers:
StringBuilder builderVal= new StringBuilder();
HttpClient httpclient = new DefaultHttpClient();
HttpPost request = new HttpPost(urlGetGrandCode);
request .setHeader("Header String","value");
request .setHeader("Header String", "value");
try {
org.apache.http.HttpResponse response = httpclient.execute(request );
Log.e("RESOONSE", "response=="+response.toString());
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader( new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
builderVal.append(line);
}
} else {
System.out.println(statusCode);
Log.e("search.class.toString()", "Failed to download file");
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
May be you output return on json as string.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments