使用sttp-Scala HTTP客户端的多部分表单数据请求

使用sttp-Scala HTTP客户端的多部分表单数据请求,scala,Scala,如何使用sttp库进行多部分表单请求。下面是示例curl请求 curl -X POST \ http://localhost:2004/v2/api/artifacts \ -H 'cache-control: no-cache' \ -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \ -F file=@/Users/username/filename

如何使用sttp库进行多部分表单请求。下面是示例curl请求

curl -X POST \
  http://localhost:2004/v2/api/artifacts \
  -H 'cache-control: no-cache' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F file=@/Users/username/filename
下面是scala代码

val request = sttp
      .multipartBody(multipart("file", new FileInputStream(filePath)))
      .post(uri"$mistApiUrl/v2/api/artifacts")
val response = request.send()
未正确发送字段
文件


问题已解决。解决方案详细信息。

fileName
需要在多部分表单数据中使用InputStream调用

val request = sttp
        .multipartBody(multipart("file", new FileInputStream(filePath)).fileName(fileName))
        .post(uri"$mistApiUrl/v2/api/artifacts")

您可以附上“未正确”发送请求吗?(例如,是一个很好的调试实用程序…)在请求对象中只设置了
Accept Encoding
头。未设置内容类型和边界。我设置了转发到mitmproxy的端口。echo“rdr pass inet proto tcp from any to any port 2004->127.0.0.1 port 8080”| sudo pfctl-ef-get-HTTP协议错误在客户端请求中:无效的HTTP请求表单(应为:authority或absolute,get:relative)是否尝试使用其他sttp后端?这可能是您当前使用的后端中的错误。在多部分中调用
fileName
函数后工作。细节