Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

HTTP GET request for mail rest API of Office 365 gives 500 error in JAVA

$
0
0

I'm trying to hit 'getMessages' api of Office 365. I tried following url and authorization header in java. But it is giving RESPONSE code 500, which is an internal server error. But when I tried the same from POSTMAN REST CLIENT, it worked perfectly fine. Can anyone suggest what I'm doing wrong?

URL url =new URL("https://outlook.office365.com/api/v1.0/me/messages/");String asB64 ="Basic "+newString(newBase64().encode(user+":"+password.getBytes()));
        println "asB64 : "+ asB64;HttpsURLConnection urlConnection =(HttpsURLConnection) url.openConnection();
        urlConnection.setRequestProperty ("Authorization", asB64);
        urlConnection.setDoOutput(true);
        urlConnection.setRequestMethod("GET");
        urlConnection.setDoInput(true);
        urlConnection.setRequestProperty("Content-Type","application/x-www-form-urlencoded,charset=UTF-8");PrintWriter printWriter =newPrintWriter(urlConnection.getOutputStream());

        printWriter.flush();InputStream inputStream = urlConnection.getInputStream();String contentType = urlConnection.getContentType();
        println "output : "+ urlConnection.getResponseCode()+" message : "+ urlConnection.getResponseMessage()+" error : "+ urlConnection.getErrorStream();


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>