none
HTTP GET request for mail rest API of Office 365 gives 500 error in java RRS feed

  • Question

  • 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 "+new String(new Base64().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 = new PrintWriter(urlConnection.getOutputStream());
    
            printWriter.flush();
    
            InputStream inputStream = urlConnection.getInputStream();
            String contentType = urlConnection.getContentType();
            println "output : " + urlConnection.getResponseCode() + " message : " + urlConnection.getResponseMessage() + " error : " + urlConnection.getErrorStream();

    Tuesday, November 25, 2014 10:51 AM

All replies