我得到了错误:
Server returned HTTP response code: 400 for URL: https://idcs-82972921e42641b1bf08128c3d93a19c.identity.c9dev2.oc9qadev.com/oauth2/v1/token
java.io.IOException: Server returned HTTP response code: 400 for URL: https://idcs-82972921e42641b1bf08128c3d93a19c.identity.c9dev2.oc9qadev.com/oauth2/v1/token
at
字符串
当我调用postman中的url
时,这个url
返回access token
。但是当我使用java
时,我的java代码抛出了exception
。
package com.shruti.getapi;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class NetClientPost {
public static void main(String[] args) {
try
{
HttpURLConnection connection=null;
String targetUrl="https://idcs-82972921e42641b1bf08128c3d93a19c.identity.c9dev2.oc9qadev.com/oauth2/v1/token";
URL url=new URL(targetUrl);
connection=(HttpURLConnection) url.openConnection();
connection.setUseCaches (false);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
connection.setRequestProperty("Authorization", "Basic aWRjcy1vZGEtOTQxN2Y5MzU2MGI5NGViOGEyZTJhNGM5YWFjOWEzZmYtdDBfQVBQSUQ6MjQ0YWU4ZTItNmY3MS00YWYyLWI1Y2MtOTExMDg5MGQxNDU2");
connection.setRequestProperty("grant-type","client_credentials");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Scope", "https://idcs-oda-9417f93560b94eb8a2e2a4c9aac9a3ff-t0.data.digitalassistant.oci.oc-test.com/api/v1");
connection.connect();
InputStreamReader in=new InputStreamReader(connection.getInputStream()); //this line throwing exception. What i am missing?
BufferedReader br =new BufferedReader(in);
String output;
while((output=br.readLine())!=null)
{
System.out.println(output);
}
connection.disconnect();
System.out.println("Last line");
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
型
1条答案
按热度按时间ckocjqey1#
可能你在HTTP请求中丢失了一些头,请验证你是否传递了端点所需的所有头。