请求在邮递员中工作正常,但在 OkHTTP 中得到 403

Ale*_*tad 5 java api rest okhttp okhttp3

我正在尝试向Genius API发出请求,但我在使用 OkHTTP 时遇到了一些问题。这是我用来拨打电话的小脚本:

public class OkHttpScript {

OkHttpClient client = new OkHttpClient();

String run(String url) throws IOException {
    Request request = new Request.Builder()
            .header("Authorization", "Bearer uDtfeAgTKL3_YnOxco4NV6B-WVZAIGyuzgH6Yp07FiV9K9ZRFOAa3r3YoxHVG1Gg")
            .url(url)
            .build();

    try (Response response = client.newCall(request).execute()) {
        return response.body().string();
    }
}

public static void main(String[] args) throws IOException {

    OkHttpScript okHttpScript = new OkHttpScript();

    String response = okHttpScript.run("http://api.genius.com/songs/378195/");

    System.out.println(response);
}


}
Run Code Online (Sandbox Code Playgroud)

运行此脚本时,出现 403 错误:

{"meta":{"status":401,"message":"This call requires an access_token. Please see: https://genius.com/developers"}}
Run Code Online (Sandbox Code Playgroud)

作为参考,这是我向 Postman 提出相同请求的图片,它有效:

邮递员图片

关于问题可能是什么的任何想法?

编辑:

不确定这是否正常,但是当我打印出构建的请求对象时,我看不到请求中有标头的迹象:

Request{method=GET, url=http://api.genius.com/songs/378195/, tag=null}
Run Code Online (Sandbox Code Playgroud)

是我得到的。这可能是问题的一部分吗?

编辑2:

没关系,做一个

System.out.println(newRequest.headers());
Run Code Online (Sandbox Code Playgroud)

给我我最初输入的内容:

Authorization: Bearer 4mfDBVzCnp2S1Fc0l0K0cfqOrQYjRrb-OHi8W1f-PPU7LNLI6-cXY2E727-1gHYR
Run Code Online (Sandbox Code Playgroud)

Ale*_*tad 2

所以我明白了我的问题是什么。我不确定其背后的详细信息,但我应该使用我的 URL,而https://api.genius.com/songs/378195/不是http://api.genius.com/songs/378195/

Postman 似乎可以使用 http,但 OkHttp 需要 https。