在日历办公室365中创建新事件时的错误请求400

时间:2015-02-20 05:44:24

标签: java office365

我的回复是"错误请求"。尝试在office 365 api中创建新事件时出错400。 这是我的代码。

System.out.println(" TESTING write to calendar");
        CommercialVO commercial = commercialService.getByCode("MBA");
        CalendrierItemVO evenement = new CalendrierItemVO();
        evenement.setDescription("TEST ");
        creerEvenement(evenement, commercial, sessionUser);
public boolean creerEvenement(CalendrierItemVO evenement) {
        HttpPost        httpPost;
        HttpResponse    httpResponse;
        StringEntity    httpEntity;

        if (evenement == null) {
            throw new IllegalArgumentException("The 'evenement' argument shan't be null.");
        } else if (evenement.getDateDebut() == null) {
            throw new IllegalArgumentException("The 'evenement' argument shall have a starting date.");
        } else if (evenement.getDateFin() == null) {
            throw new IllegalArgumentException("The 'evenement' argument shall have an ending date.");
        }


        System.out.println("Creating event desciprion: " + evenement.getDescription() + " titre:" +evenement.getTitre() + " uid:" + evenement.getUid() + " date creation: " + evenement.getDateCreation() + " date debut:"  + evenement.getDateDebut());
        this.organisationService.ensureFreshToken();
System.out.println(" Creatingf evenement for office365"  +gson.toJson(evenement, CalendrierItemVO.class));
        try {
            System.out.println(" Office365 events:" + this.organisationConfiguration.getOffice365CalendarEndpoint() + "/calendars/" + this.configuration.getIdCalendrier() + "/events");
            httpPost = new HttpPost(this.organisationConfiguration.getOffice365CalendarEndpoint() + "/calendars/" + this.configuration.getIdCalendrier() + "/events");


            httpEntity = new StringEntity("{'Subject': 'Discuss the Calendar REST API','Body': {'ContentType': 'HTML','Content': 'I think it will meet our requirements!'},'Start': '2015-02-20T05:21:04Z','End': '2015-02-20T05:21:04Z','Location': { 'DisplayName':'ConferenceRoom 1' },'ShowAs': 'Busy','Attendees': [{ 'EmailAddress': { 'Name': 'Alex Darrow', 'Address': 'alex11d@contoso.com' },'Type': 'Required' },{ 'EmailAddress': { 'Name': 'Anne Wallace', 'Address': 'annew@contoso.com'}, 'Type': 'Optional'},{'EmailAddress': { 'Name': 'Conference Room 1', 'Address': 'conf1@contoso.com' },'Type': 'Resource' }]}", "UTF-8");


            httpPost.setEntity(httpEntity);
            System.out.println(" Office365 events test1 ");

            httpPost.addHeader("authorization", "BEARER " + this.organisationConfiguration.getOffice365AccessToken());
            httpResponse = this.httpClient.execute(httpPost);
            System.out.println(" Office365 events test2 " + httpResponse.getStatusLine().getReasonPhrase() + " "+ httpResponse.getStatusLine().getStatusCode());
            httpResponse.getEntity().getContent().close();
            if (httpResponse.getStatusLine().getStatusCode() == 201) {
                System.out.println(" Office365 eventsstatus 201 ");
                return true;
            }
        } catch (IOException e) {
            System.out.println(" Exetpion 1:  " + e.getMessage());
            e.printStackTrace();
        } catch (UnsupportedCharsetException e) {
            System.out.println(" Exetpion 2:  " + e.getMessage());
            e.printStackTrace();
        }

        return false;
    }

转储

Creating event desciprion: TEST JRA ? TU VOIS ? titre:TEST uid:null date creation: null date debut:java.util.GregorianCalendar[time=1424410735062,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Muscat",offset=14400000,dstSavings=0,useDaylight=false,transitions=3,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2015,MONTH=1,WEEK_OF_YEAR=8,WEEK_OF_MONTH=3,DAY_OF_MONTH=20,DAY_OF_YEAR=51,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=3,AM_PM=0,HOUR=9,HOUR_OF_DAY=9,MINUTE=38,SECOND=55,MILLISECOND=62,ZONE_OFFSET=14400000,DST_OFFSET=0]
 Creatingf evenement for office365{"IsAllDay":false,"Subject":"TEST","Start":"2015-02-20T05:38:55Z","End":"2015-02-20T06:38:55Z","Body":{"ContentType":"HTML","Content":"TEST JRA ? TU VOIS ?"}}
 Office365 events:https://outlook.office365.com/api/v1.0/me/calendars/Calendarid/events
 Office365 events test1 
 Office365 events test2 Bad Request 400

我哪里出错了,如何解决这个错误的请求问题?

1 个答案:

答案 0 :(得分:1)

尝试将您的内容类型设置为"application/json"