-1
Office 365의 'getMessages'API를 사용하려고합니다. 자바에서 url 및 인증 헤더를 다음과 같이 시도했습니다. 그러나 내부 서버 오류 인 RESPONSE 코드 500을 제공합니다. 그러나 POSTMAN REST CLIENT에서 같은 것을 시도해 보았을 때, 그것은 완벽하게 정상적으로 작동했습니다. 누구든지 내가 뭘 잘못하고 있다고 제안 할 수 있습니까?HTTP GET 요청으로 java에서 500 오류가 발생합니다.
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();
(그대로 POSTMAN REST 클라이언트가 응답 다음 부여합니다) 요청의 출력되어야 다음 : I가 Unirest for Java을 사용하여이 문제를 해결
{"@odata.context":"https://outlook.office365.com/api/v1.0/$metadata#Me/Messages","value":[{"@odata.id":"https://outlook.office365.com/api/v1.0/Users('[email protected]')/Messages('AAMkADdkMTEyY2RhLTA5YTItNDM0OS05NTVjLWZhNGI2OWUxZjBkOABGAAAAAACFIzMHuQuLQ6LXFS-gt6NSBwBgChXEzbNhRbE9LyPei8StAAAAAAEMAABgChXEzbNhRbE9LyPei8StAAACWUu4AAA=')","@odata.etag":"W/\"CQAAABYAAABgChXEzbNhRbE9LyPei8StAAACWUs2\"","Id":"AAMkADdkMTEyY2RhLTA5YTItNDM0OS05NTVjLWZhNGI2OWUxZjBkOABGAAAAAACFIzMHuQuLQ6LXFS-gt6NSBwBgChXEzbNhRbE9LyPei8StAAAAAAEMAABgChXEzbNhRbE9LyPei8StAAACWUu4AAA=","ChangeKey":"CQAAABYAAABgChXEzbNhRbE9LyPei8StAAACWUs2","Categories":[],"DateTimeCreated":"2014-11-25T06:34:35Z","DateTimeLastModified":"2014-11-25T06:34:35Z","Subject":"test me","BodyPreview":"Hello..\r\n\r\n- Piyusha","Body":{"ContentType":"HTML","Content":"\r\n\r\n\r\n\r\n\r\n\r\n\r\n
\r\n
Hello..
\r\n
\r\n
\r\n- \r\nPiyusha
\r\n
\r\n
\r\n\r\n\r\n"},"Importance":"Normal","HasAttachments":false,"ParentFolderId":"AAMkADdkMTEyY2RhLTA5YTItNDM0OS05NTVjLWZhNGI2OWUxZjBkOAAuAAAAAACFIzMHuQuLQ6LXFS-gt6NSAQBgChXEzbNhRbE9LyPei8StAAAAAAEMAAA=","From":{"EmailAddress":{"Address":"[email protected]","Name":"Piyusha"}},"Sender":{"EmailAddress":{"Address":"[email protected]","Name":"Piyusha"}},"ToRecipients":[{"EmailAddress":{"Address":"[email protected]","Name":"Test2"}}],"CcRecipients":[],"BccRecipients":[],"ReplyTo":[],"ConversationId":"AAQkADdkMTEyY2RhLTA5YTItNDM0OS05NTVjLWZhNGI2OWUxZjBkOAAQADdgtnhCYExDhAoxDCJGdbk=","DateTimeReceived":"2014-11-25T06:34:35Z","DateTimeSent":"2014-11-25T06:33:57Z","IsDeliveryReceiptRequested":null,"IsReadReceiptRequested":false,"IsDraft":false,"IsRead":false},{"@odata.id":"https://outlook.office365.com/api/v1.0/Users('[email protected]')/Messages('AAMkADdkMTEyY2RhLTA5YTItNDM0OS05NTVjLWZhNGI2OWUxZjBkOABGAAAAAACFIzMHuQuLQ6LXFS-gt6NSBwBgChXEzbNhRbE9LyPei8StAAAAAAEMAABgChXEzbNhRbE9LyPei8StAAACWUu3AAA=')","@odata.etag":"W/\"CQAAABYAAABgChXEzbNhRbE9LyPei8StAAACWUs1\"","Id":"AAMkADdkMTEyY2RhLTA5YTItNDM0OS05NTVjLWZhNGI2OWUxZjBkOABGAAAAAACFIzMHuQuLQ6LXFS-gt6NSBwBgChXEzbNhRbE9LyPei8StAAAAAAEMAABgChXEzbNhRbE9LyPei8StAAACWUu3AAA=","ChangeKey":"CQAAABYAAABgChXEzbNhRbE9LyPei8StAAACWUs1","Categories":[],"DateTimeCreated":"2014-11-24T05:06:24Z","DateTimeLastModified":"2014-11-24T05:06:24Z","Subject":"Test Email for API","BodyPreview":"Hi,\r\nThis is test email for API testing\r\n\r\n- Piyusha","Body":{"ContentType":"HTML","Content":"\r\n\r\n\r\n\r\n\r\n\r\n\r\n
\r\n
\r\n
Hi,
\r\n
This is test email for API testing
\r\n
\r\n
\r\n- \r\nPiyusha
\r\n
\r\n
\r\n\r\n\r\n"},"Importance":"Normal","HasAttachments":false,"ParentFolderId":"AAMkADdkMTEyY2RhLTA5YTItNDM0OS05NTVjLWZhNGI2OWUxZjBkOAAuAAAAAACFIzMHuQuLQ6LXFS-gt6NSAQBgChXEzbNhRbE9LyPei8StAAAAAAEMAAA=","From":{"EmailAddress":{"Address":"[email protected]","Name":"Piyusha"}},"Sender":{"EmailAddress":{"Address":"[email protected]","Name":"Piyusha"}},"ToRecipients":[{"EmailAddress":{"Address":"[email protected]","Name":"Test2"}}],"CcRecipients":[],"BccRecipients":[],"ReplyTo":[],"ConversationId":"AAQkADdkMTEyY2RhLTA5YTItNDM0OS05NTVjLWZhNGI2OWUxZjBkOAAQAJE40Qula0HBl35-_7JOrmM=","DateTimeReceived":"2014-11-24T05:06:24Z","DateTimeSent":"2014-11-24T05:05:55Z","IsDeliveryReceiptRequested":null,"IsReadReceiptRequested":false,"IsDraft":false,"IsRead":false}]}
두 클라이언트가 제출 한 헤더를 비교하는 것이 좋습니다. 명확하지 않은 경우 여기에 헤더를 게시하십시오 (물론 인증 헤더가 없습니다). 또한 인증을 위해 ADAL 라이브러리를 사용하는 것이 좋습니다. –