这是我的 api 密钥:7b5e30851a9285340e78c201c4e4ab99
我正在尝试连接到 TMDB api:这是我的代码:
package movieDBapiconnnection;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class connection {
public static void main(String[] args) throws Exception{
URL url = new URL("http://api.themoviedb.org/3/movie/550?api_key=7b5e30851a9285340e78c201c4e4ab99/3/movie/550");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
con.setRequestMethod("GET");
con.setRequestProperty("Content-Type", "application/json");
BufferedReader br = new BufferedReader(new InputStreamReader((con.getInputStream())));
String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
}
}
但它总是向我显示以下错误:
线程“主”java.io.IOException 中的异常:服务器返回 HTTP 响应代码:URL 的 401:http ://api.themoviedb.org/3/movie/550?api_key=7b5e30851a9285340e78c201c4e4ab99/3/movie/550 at sun。 net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) at movieDBapiconnnection.connection.main(connection.java:17)