将curl请求(POST)转换为标量代码

问题描述 投票:2回答:1

我有以下要在Scala中实现的curl请求。

curl -u“用户名” -X POST“ https://post_url.com” -H“内容类型:multipart / form-data” -F“ xmlRequest = @ / home/@file.xml; type = text / xml”] >

我尝试了以下操作,但请求不正确。

val client = new DefaultHttpClient()
val requestEntity = MultipartEntityBuilder.create().addBinaryBody("xmlRequest",
  new File("/home/@file.xml")).build()
val post = new HttpPost("https://post_url.com")
post.addHeader(BasicScheme.authenticate(new
      UsernamePasswordCredentials(username, password), "UTF-8", false))
post.addHeader("Content-Type", "multipart/form-data")
post.setEntity(requestEntity)
val response = client.execute(post)
println(response.getStatusLine)
    

我有以下要在Scala中实现的curl请求。 curl -u“用户名” -X POST“ https://post_url.com” -H“内容类型:multipart / form-data” -F“ xmlRequest = @ / home/@file.xml; ...

scala curl post xmlhttprequest apache-httpclient-4.x
1个回答
0
投票

我已经能够通过使用另一个addBinaryBody函数来解决我的问题。

© www.soinside.com 2019 - 2024. All rights reserved.