Issue with Integration Between WebClient (Java Spring WebFlux) and qBittorrent API (Adding New Torrent)

I’m trying to integrate a Java 21 application with WebClient and the qBittorrent API. However, I’m encountering difficulties. When I perform the integration using curl, it works successfully. The same is true when I use Postman or the OkHttp library. I also attempted to use the RestTemplate, but without success.

I’m running qBittorrent with the following Docker image: qbittorrentofficial/qbittorrent-nox:4.6.5-2. Here’s my Docker Compose configuration:

services:
  qbittorrent-nox:
    container_name: qbittorrent-nox
    environment:
      - QBT_EULA=accept
      - QBT_VERSION=latest
      - QBT_WEBUI_PORT=8081
    image: qbittorrentofficial/qbittorrent-nox:4.6.5-2
    ports:
      - 6881:6881/tcp
      - 6881:6881/udp
      - 8081:8081/tcp
    read_only: true
    restart: always
    stop_grace_period: 30m
    tty: true
    volumes:
      - /home/passella/.qbittorrent-nox/config:/config
      - /mnt/sda/:/mnt/sda/
      - /mnt/sdb/:/mnt/sdb/
      - /mnt/qbittorrent/:/mnt/qbittorrent/

Currently, I can successfully integrate with the API using curl. For example:

curl --location 'http://localhost:8081/api/v2/torrents/add' 
  --header 'Cookie: SID=MY-SID' 
  --form 'savepath="/mnt/sdb/stream/series"' 
  --form 'urls="https://torcache.net/torrent/3B1A1469C180F447B77021074DBBCCAEF62611E7.torrent"'

I can also successfully integrate using Postman. However, when I make the same call from my Java application, I receive the following response:

<200 OK OK,Fails.,[connection:"keep-alive", content-length:"6", content-security-policy:"default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; script-src 'self' 'unsafe-inline'; object-src 'none'; form-action 'self'; frame-ancestors 'self';", content-type:"text/plain; charset=UTF-8", cross-origin-opener-policy:"same-origin", date:"Fri, 09 Aug 2024 22:29:22 GMT", referrer-policy:"same-origin", x-content-type-options:"nosniff", x-frame-options:"SAMEORIGIN", x-xss-protection:"1; mode=block"]>

Additionally, when I check the container logs, I see this error:

bool Http::RequestParser::parseRequestLine(const QString&) invalid http header: "27"
Http::RequestParser::ParseResult Http::RequestParser::doParse(const QByteArray&) header parsing error
Requisição ruim do HTTP, fechando o soquete. IP: ::ffff:172.18.0.1

Here’s my Java code snippet:

private void processItem(final String cookie, final Map.Entry<Item, Data> item) {
    final var webClient = clientBuilder.baseUrl("https://localhost:8081").build();
    webClient
            .post()
            .uri("/api/v2/torrents/add")
            .header("Cookie", "SID=%s".formatted(cookie))
            .contentType(MediaType.MULTIPART_FORM_DATA)
            .body(BodyInserters
                    .fromMultipartData("savepath", item.getValue().dockerPath())
                    .with("urls", item.getKey().link())
            )
            .retrieve()
            .toEntity(String.class)
            .subscribe(System.out::println);
}

I’m using Java 21, Spring Boot 3.3.2, and Gradle. My dependencies are as follows:

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-hateoas'
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    testImplementation 'io.projectreactor:reactor-test'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

If you have any further questions or need additional details, feel free to ask!

I attempted to use Rest Template for the integration, but encountered the same error. When using Postman, it generates two types of Java code: one with the UniRest library and another with the OkHttp library. While UniRest leads to the same problem, the integration succeeds when using the OkHttp library. However, my intention is to use WebClient or Rest Template for the solution. The API is functional, as mentioned in the problem. I can test it using curl:

curl --location 'http://localhost:8081/api/v2/torrents/add' 
  --header 'Cookie: SID=MY-SID' 
  --form 'savepath="/mnt/sdb/stream/series/"' 
  --form 'urls="https://torcache.net/torrent/3B1A1469C180F447B77021074DBBCCAEF62611E7.torrent"'

But the idea is to achieve the integration using the Java solution.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật