Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bodyPublisher.contentLength() Always returns -1 #8

Open
ghost opened this issue Apr 9, 2024 · 0 comments
Open

bodyPublisher.contentLength() Always returns -1 #8

ghost opened this issue Apr 9, 2024 · 0 comments

Comments

@ghost
Copy link

ghost commented Apr 9, 2024

    public List<TorrentContent> addTorrent(Path torrentPath) {
        try (HttpClient httpClient = HttpClient
                .newBuilder()
                .version(HttpClient.Version.HTTP_1_1)
                .build()) {
            MultipartFormDataBodyPublisher bodyPublisher = new MultipartFormDataBodyPublisher();
            bodyPublisher.addFile("torrents",torrentPath);
//            bodyPublisher.addStream("torrents", "a.torrent", () -> stream, "application/octet-stream");
            String uri = "http://127.0.0.1/1.php";//qbBaseUrl + "/api/v2/torrents/add";
            System.out.println("length: " + bodyPublisher.contentLength()  + " uri : " + uri + " type:" + bodyPublisher.contentType());
            HttpRequest httpRequest = HttpRequest.newBuilder()
                    .uri(URI.create(uri))
                    .expectContinue(true)
                    .version(HttpClient.Version.HTTP_1_1)
                    .method("POST",bodyPublisher)
                    .build();
            HttpResponse<String> response = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
            System.out.println("body: " + response.body());
        } catch (IOException | InterruptedException e) {
            throw new RuntimeException(e);
        }

        return null;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants