我需要帮助在Java中发出cURL POST请求(到spotifyapi)。我把我的解决办法解释得太离谱了
this article
.
基于此,我尝试了以下方法:
String command = "curl -X 'POST' -H 'Authorization: Basic Base64TokenHere' -d 'grant_type=client_credentials' 'https://accounts.spotify.com/api/token'";
try {
Process process = Runtime.getRuntime().exec(command);
process.getInputStream();
BufferedReader br = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String output;
StringBuffer response = new StringBuffer();
while ((output = br.readLine()) != null) {
response.append(output);
}
br.close();
System.out.println(response.toString())
} catch (IOException ioException) {
ioException.printStackTrace();
}
它似乎工作,但我没有得到回应,是的,cURL命令本身的工作。
如果你有任何关于为什么这是不提供任何输出像它通常,请告诉我。
{
"access_token": "NgCXRKc...MzYjw",
"token_type": "bearer",
"expires_in": 3600,
}
如果有一个替代我的解决方案,我应该用它来代替提供一个答案。