400错误请求:“您的请求无法完成” - 与邮递员的ucwa批量请求

时间:2017-05-03 08:12:29

标签: skype-for-business ucwa batching

我用邮递员发送了这批请求:

POST /ucwa/oauth/v1/applications/105177669305/batch HTTP/1.1
Host: lync.myDomain.com
Accept: multipart/batching
Content-Type: multipart/batching;boundary=6555373f-c163-b72d-5c00-c3cc6cb9cd52
Authorization: Bearer cwt=AAEBHAEFAAAAAAAFFQAAAJFDb5_gw6wKmbRiI5oNABENAxu_zcjj9Rt7KWK3RkJSKCAvAPgyCThFvNa0lFTBPm5usuFxhbNo5VqemqSOoI-qWc_fihdoYI4G_bjjSS1AgNENAxu_zcjj9Rt7KWK3RkJSI
X-Requested-With: xmlhttprequest
Cache-Control: no-cache
Postman-Token: 57195c61-6b6f-0db9-5760-0af268fe7d55

--6555373f-c163-b72d-5c00-c3cc6cb9cd52
Content-Type:application/http;msgtype=request
GET /ucwa/oauth/v1/applications/10513269305/people/contacts HTTP/1.1
Host:lync.myDomain.com
Accept:application/json

--6555373f-c163-b72d-5c00-c3cc6cb9cd52
Content-Type:application/http;msgtype=request
GET /ucwa/oauth/v1/applications/10513269305/me/presence HTTP/1.1
Host:lync.myDomain.com
Accept:application/json

--6555373f-c163-b72d-5c00-c3cc6cb9cd52--

并获得响应状态“400 Bad Request”,其中“您的请求无法完成”。信息。我错过了一些标题吗?如果您知道我收到此错误的原因,请告诉我。

2 个答案:

答案 0 :(得分:0)

来自w3.org

HTTP Code 400 Bad Request表示;

  

由于格式错误,服务器无法理解该请求   句法。客户端不应该重复请求   修改

检查您的请求语法。您的服务器期望什么样的请求格式?你能检查服务器日志吗?

答案 1 :(得分:0)

Lines need to end with Windows style line endings (\r\n), and should follow the format which is not even mentioned in the documentation

以下代码是从UCWA样本中的batch.js转换而来的,https://github.com/OfficeDev/skype-docs/blob/master/Skype/UCWA/samples/scripts/Batch.js

Batch中的请求限制为100。

@Test
public void test() {
    List<String> parts = new ArrayList<>();
    String boundary = "77f2569d-c005-442b-b856-782305305e5f";

    for (int i = 0; i < 100; i++) {
        parts.add(createDataPart(boundary));
    }

    String data = parts.stream().collect(Collectors.joining("\r\n"));
    data += "\r\n\r\n--" + boundary + "--\r\n";

    try {
        HttpResponse<String> response =
            Unirest.post("https://lyncweb.example.com/ucwa/oauth/v1/applications/10820256145/batch")
            .header("authorization", "Bearer cwt=CCCCHAEFAAAAAAAFFQAAANz03DsuQ6xAB-U7K3yFAACBEBUTVWulRKhftCre06OKSveCAgghgyBAJ_THbZjk1M3ICsm1apTszG7HcKGll6HUDlc4i_fEEoYIU0vz-ojC1QgNEBDrIobFox9WpyA_EhuC5Mk")
            .header("content-type", "multipart/batching;boundary=" + boundary)
            .header("accept", "multipart/batching")
            .body(data)
            .asString();

        System.out.println("Response1 \r" + response.getBody());

    } catch (UnirestException e) {
        e.printStackTrace();
    }

}

String createDataPart(String boundary) {
    String dataPart = "\r\n--" + boundary;
    dataPart += "\r\nContent-Type: application/http; msgtype=request\r\n";
    dataPart += "\r\n" + "GET /ucwa/oauth/v1/applications/10820256145/people/test.user@example.com/presence HTTP/1.1";
    dataPart += "\r\n" + "Host: " + "lyncweb.example.com";
    dataPart += "\r\n" + "Accept: " + "application/json";

    //if (part.Data) {
    //    dataPart += "\r\n" + "Data: " + JSON.stringify(part.Data);
    //}
    dataPart += "\r\n";
    return dataPart;
}