从 Vert.x WebClient 发送多部分/表单数据到 Django 休息框架

问题描述 投票:0回答:1

尝试将文档和一些数据从我的 vert.x(客户端)发送到 django rest-framework(服务器端): 代码服务器端是:

@api_view(['POST'])
@parser_classes([MultiPartParser, FormParser])
def quick_indexing(request):
    
    data = request.data
    print(data)  # print the entire request data dictionary
    test_value = data.get("test")
    if test_value:
        return Response(f"test attribute value: {test_value}")
    else:
        return Response("test attribute not found")

代码客户端:

Vertx vertx = Vertx.vertx();
        WebClient client = WebClient.create(vertx);
        Buffer file = vertx.fileSystem().readFileBlocking("C:/Users/houth/CIN Hassan.pdf");
        MultipartForm form = MultipartForm.create()
            .attribute("test", "succed");
// Send a POST request with the file and form data
        client.postAbs("http://localhost:8000/quick-indexing")
            .putHeader(String.valueOf(HttpHeaders.CONTENT_TYPE), "multipart/form-data")
            .sendMultipartForm(form,
                ar -> {
                    if (ar.succeeded()) {
                        // Handle the response
                        HttpResponse<Buffer> response = ar.result();
                        System.out.println("Status code: " + response.statusCode());
                        System.out.println("Response body: " + response.bodyAsString());
                    } else {
                        // Handle the failure
                        Throwable cause = ar.cause();
                        System.err.println("Request failed: " + cause.getMessage());
                    }
                });
        System.out.println("end");

---> 客户端的结果是:

end
Status code: 200
Response body: "test attribute not found"
[ERROR] 2023-04-08 01:39:22.881  invalid version format: <!DOCTYPE
java.lang.IllegalArgumentException: invalid version format: <!DOCTYPE
    at io.netty.handler.codec.http.HttpVersion.<init>(HttpVersion.java:116) ~[netty-codec-http-4.1.86.Final.jar:4.1.86.Final]
    at io.netty.handler.codec.http.HttpVersion.valueOf(HttpVersion.java:78) ~[netty-codec-http-4.1.86.Final.jar:4.1.86.Final]

---> 服务器端的结果是:

<QueryDict: {}>
[08/Apr/2023 01:39:22] "POST /quick-indexing HTTP/1.1" 200 26
[08/Apr/2023 01:39:22] code 400, message Bad request syntax ('9d')
[08/Apr/2023 01:39:22] "9d" 400 -

----> 问题是如果我从邮递员调用 api 它会成功

CDL

将带有文件的数据从 vert.x webclient 发送到 api rest 框架

java spring django-rest-framework vert.x vert.x-webclient
1个回答
0
投票

您是否确保从vert.发送的表格? X 不为空

© www.soinside.com 2019 - 2024. All rights reserved.