0

我正在尝试使用 Android 中的 Exchange 2010 为您的会议应用程序构建一本书。我正在使用CorporateContacts来熟悉 activesync。到目前为止,我已经设法让 ResolveRecipients 、 SendMail 和 FolderSync 命令正常工作。但是,当我尝试上传会议请求时,我收到 400 错误请求错误。我 以此 为参考。

我的 xml

<?xml version="1.0" encoding="utf-8"?>
<Sync xmlns:calendar="Calendar" xmlns="AirSync">
    <Collections>
        <Collection>
            <SyncKey>1425334024</SyncKey>
            <CollectionId>4</CollectionId>
            <GetChanges>1</GetChanges>
            <Commands>
                <Add>
                    <ClientId>5644895</ClientId>
                    <ApplicationData>
                         <calendar:TimeZone>tv7//ygAVQBUAEMAKwAwADUAOgAzADAAKQAgAEMAaABlAG4AbgBhAGkALAAgAEsAbwBsAGsAYQB0AGEALAAgAE0AdQAAAAAAAAAAAAAAAAAAAAAAAAAAACgAVQBUAEMAKwAwADUAOgAzADAAKQAgAEMAaABlAG4AbgBhAGkALAAgAEsAbwBsAGsAYQB0AGEALAAgAE0AdQAAAAAAAAAAAAAAAAAAAAAAAAAAAA==</calendar:TimeZone>
                        <calendar:StartTime>20130109T100000Z</calendar:StartTime>
                        <calendar:Subject>TestMeeting</calendar:Subject>
                        <calendar:UID>040000008200E90074C5B7101A82E0080000000036BD76EAAAD5CA01000000000000000010000000C45185F686A5D542B20BF2CE2F477D55</calendar:UID>
                        <calendar:Attendees>
                            <calendar:Attendee>
                                <calendar:Email>Test@test.com</calendar:Email>
                                <calendar:Name>JohnDoe</calendar:Name>
                                <calendar:AttendeeStatus>0</calendar:AttendeeStatus>
                                <calendar:AttendeeType>1</calendar:AttendeeType>
                            </calendar:Attendee>
                        </calendar:Attendees>
                        <calendar:Location>My Office</calendar:Location>
                        <calendar:EndTime>20130109T110000Z</calendar:EndTime>
                        <calendar:Sensitivity>0</calendar:Sensitivity>
                        <calendar:BusyStatus>1</calendar:BusyStatus>
                        <calendar:AllDayEvent>0</calendar:AllDayEvent>
                        <calendar:MeetingStatus>1</calendar:MeetingStatus>
                    </ApplicationData>
                </Add>
            </Commands>
        </Collection>
    </Collections>
</Sync>

CreateHTTPPost 函数

private HttpPost createHttpPost(String uri, String requestXML,
            boolean includePolicyKey) throws Exception {

        // Set the common headers
        HttpPost httpPost = new HttpPost(uri);
        httpPost.setHeader("User-Agent", "Android");
        httpPost.setHeader("Accept", "*/*");
        httpPost.setHeader("Content-Type", "application/vnd.ms-sync.wbxml");
        //httpPost.setHeader("Content-Type", "message/rfc822");//message/rfc822



        // If we are connecting to Exchange 2010 or above
        // Lets tell the Exchange server that we are a 12.1 client
        // This is so we don't have to support sending of additional
        // information in the provision method
        if(getActiveSyncVersionFloat() >= 14.0)
            httpPost.setHeader("MS-ASProtocolVersion", "12.1");
        // Else set the version to the highest version returned by the
        // Exchange server
        else
            httpPost.setHeader("MS-ASProtocolVersion", getActiveSyncVersion());


        //Log.d(TAG, mActiveSyncVersion);
        httpPost.setHeader("Accept-Language", "en-us");
        httpPost.setHeader("Authorization", mAuthString);

        // Include policy key if required
        if (includePolicyKey)
            httpPost.setHeader("X-MS-PolicyKey", mPolicyKey);

        // Add the XML to the request
        if (requestXML != null) {
            //Log.d(TAG, requestXML);
            // Set the body
            // Convert the XML to WBXML
            ByteArrayInputStream xmlParseInputStream = new ByteArrayInputStream(
                    requestXML.toString().getBytes());

            java.io.ByteArrayOutputStream output = new java.io.ByteArrayOutputStream();
            wbxml.convertXmlToWbxml(xmlParseInputStream, output);
            byte[] bytes = output.toByteArray();

            ByteArrayEntity myEntity = new ByteArrayEntity(bytes);
            myEntity.setContentType("application/vnd.ms-sync.wbxml");
            httpPost.setEntity(myEntity);
        }
        return httpPost;
    }

有没有我遗漏的标题?或者 xml 有任何错误吗?如果有人可以提供一些启发,我将非常感激。我在标头中使用 activesync 版本 12.1。

4

1 回答 1

0

xml 看起来不错。确保您正确地从 xml 转换为 wbxml。要仔细检查,请尝试转换回 xml 并查看是否返回原始字符串。

于 2013-01-28T10:08:48.023 回答