我在这里想到的唯一解决方案是使用TypeFile类:
TypedFile tarTypeFile = new TypedFile("application/tar", myFile);和接口(这次没有显式设置Content-Type标头):
@POST("/build")Response build(@Query("t") String tag, @Query("q") boolean quiet, @Query("nocache") boolean nocache, @Body TypedInput inputStream);使用我自己的TypedInput实现会导致模糊的EOF异常,即使我提供了length()。
public class TarArchive implements TypedInput { private File file; public TarArchive(File file) { this.file = file; } public String mimeType() { return "application/tar"; } public long length() { return this.file.length(); } public InputStream in() throws IOException { return new FileInputStream(this.file); }}另外,在解决此问题时,我尝试使用最新的Apache Http客户端而不是OkHttp,这会导致“ Content-
Length标头已存在”错误,即使我没有明确设置该标头也是如此。



