1

当我使用 curl 执行 POST 请求时,它看起来是这样的:

curl -k -X POST \    
--header "Content-Type: application/x-www-form-urlencoded" \    
--header "Accept: application/json" \    
--data-urlencode "grant_type=urn:ibm:params:oauth:grant-type:apikey" \    
--data-urlencode "apikey=<somekey>" \    
"https://iam.bluemix.net/identity/token"

scalaj-http库中,我知道我们可以添加header,但我没有看到添加data-urlencode选项的方法。我怎样才能添加这个?我需要它才能使我的 POST 请求成功。

4

1 回答 1

2

postForm像这样试试

Http("https://iam.bluemix.net/identity/token")
  .header("Content-Type", "application/x-www-form-urlencoded")
  .header("Accept", "application/json")
  .postForm(Seq(
    "grant_type" -> "urn:ibm:params:oauth:grant-type:apikey", 
    "apikey" -> "somekey"))
  .asString
于 2019-08-12T13:49:47.590 回答