Q: change in response code compared between java client and browser client I'm trying to access one drive for business oAuth v2.0 through java code. A/c to the specification given by one drive api authenticatoin : https://dev.onedrive.com/auth/aad_oauth.htm, 
we need to get authorization code after registering the application in azure ad in order to access onedrive for business. 
So i have tried it in  Advanced Rest Client (Chrome extension) and was successfully getting the auth code in the redirect uri(with response code 302 which is expected). 
But, when i try to implement it in java using httpclient/URLConnection/httpURLConection/default httpURLConnection/jsoup, the response code which i get is 200 OK and i couldn't find the header field "Location" (in which we can get auth code along with redirect uri).
Is there any specific changes that should be made for response in java client to be as exact as in ARC??
Does java methods just discard these elements?

A: Based on my understanding, you want to request an URL without redirect automatically like browser.
As I know, the Apache HttpClient will do the following redirect with the response code 30x if not set the ClientPNames.HANDLE_REDIRECTS='http.protocol.handle-redirects' with a boolean value, please see the doc http://hc.apache.org/httpcomponents-client-4.2.x/tutorial/html/httpagent.html#d5e1169.

ClientPNames.HANDLE_REDIRECTS='http.protocol.handle-redirects':  defines whether redirects should be handled automatically. This parameter expects a value of type java.lang.Boolean. If this parameter is not set HttpClient will handle redirects automatically.

However, I don't think the URLConnection, HTTPURLConnection & HttpsURLConnection will automatically redirect, even jsoup implemented by them.
Here are some code shown how to prevent redirect automatically and extract the header.
1.Using HttpClient
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS, false);
HttpGet request = new HttpGet("<URL>");
HttpResponse response = client.execute(request);

//get all headers       
Header[] headers = response.getAllHeaders();
for (Header header : headers) {
    System.out.println("Key : " + header.getName() + " ,Value : " + header.getValue());
}

2.Using HttpURLConnection
URL url = new URL("<URL>");
URLConnection conn = url.openConnection();

//get all headers
Map<String, List<String>> map = conn.getHeaderFields();
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
    System.out.println("Key : " + entry.getKey() + " ,Value : " + entry.getValue());
}

Hope it helps. Best Regards.
