我实现了几乎与HttpBuilder-NG示例中列出的代码完全相同的代码,但它对我不起作用。由于某些原因,它不会将multipart识别为方法。来自库https://http-builder-ng.github.io/http-builder-ng/asciidoc/html5/#_multipart创建者的示例
def uploadFileNG(String targetTestId, String filePath) {
File someFile = new File(filePath)
OkHttpBuilder.configure {
request.uri = blazeUrl
}.post {
request.uri.path = "/api/latest/tests/${targetTestId}/files"
request.contentType = "multipart/form-data"
request.body = multipart {
field 'name', 'This is my file'
part 'file', someFile.getName(), 'text/plain', someFile
}
request.encoder 'multipart/form-data', OkHttpEncoders.&multipart
}
}发布于 2017-08-18 20:34:57
需要静态导入(在request.body配置中) multipart方法(我将更新文档以使其更明确)。
对于您的示例,这将是import static groovyx.net.http.MultipartContent.multipart。
https://stackoverflow.com/questions/45744951
复制相似问题