如何使用UCWA 2.0正确发送批处理请求?

时间:2019-05-10 10:18:34

标签: ucwa

我正在编写UCWA应用程序,以接收每个用户的状态和注释。目前,我订阅了所有需要的联系人,启动了事件流,然后收到了大约200个事件。我使用for循环遍历它们以接收我的联系人状态和备注,这意味着我发送了大约100个请求,根据Microsoft文档,这可能会耗尽移动设备的电量或影响性能。我想使用批处理来解决此问题。

<?php
include("db_connect.php");

if(isset($_POST['save']))
{
// Please give for me code
... 
//
}
?>

在搜索了Microsoft的文档之后,我找不到有关如何格式化批处理请求的任何帮助。我尝试按照提供的示例之一进行操作,但是却收到如下所示的400错误:

onEvent(events) {
    for (var i in events) {
        const event = events[i]
        switch (event.link.rel) { // 250 events filtered down to around 100
            case 'contactPresence':
            case 'presence':
                this.setPresence(event.link.href, this.getUser(event))
                break
            case 'contactNote':
            case 'note':
                this.setNote(event.link.href, this.getUser(event))
                break
            case 'presenceSubscription':
                ...
                break
        }
    }
}

最终,我尝试按照从https://drive.google.com/file/d/1tDKPbZ_gaNZrcYHt-tQtcF-TH0hMzGFi/view?usp=sharing中看到的格式发送一批,如下所示:

{
    "code":"BadRequest",
    "message":"Your request couldn\u0027t be completed."
}

这是请求有效负载:

batch() {
    const boundary = Date.now()
    fetch(this.hub + this.response._links.batch.href, {
        method: 'POST',
        headers: {
            Accept: 'multipart/batching',
            Authorization: `Bearer ${this.token}`,
            'Content-Type': `multipart/batching;boundary=${boundary}`
        },
        body: `--${boundary}\r\nContent-Type: application/http; msgtype=request\r\n\r\nGET ${this.response._links.self.href + '/people/contacts'} HTTP/1.1\r\nAccept: application/json\r\nHost: ${this.hub}\r\n\r\n--${boundary}--`
    }).then(r => r.json())
    .then(data => console.log(data))
}

这将返回500错误,例如:

--1557482296198
Content-Type: application/http; msgtype=request

GET /ucwa/oauth/v1/applications/103357029549/people/contacts HTTP/1.1
Accept: application/json
Host: https://webpoolam41e02.infra.lync.com

--1557482296198--

我花了很长时间寻找答案,但是找不到有效的答案。

有人知道如何正确格式化批处理请求吗?

1 个答案:

答案 0 :(得分:1)

我找到了自己问题的答案。事实证明,最后一批需要3个换行符:

\r\n\r\n\r\n

而不是2:

\r\n\r\n
相关问题