【发布时间】:2020-10-05 21:39:38
【问题描述】:
我有以下 curl 请求,我正在尝试在 scala 中实现。
curl -u "username" -X POST "https://post_url.com" -H "Content-Type: 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 post xmlhttprequest apache-httpclient-4.x