Skip to content
Advertisement

Request working fine in postman, but getting a 403 in OkHTTP

I’m trying to make a request to the Genius API, but I’m running into some issues using OkHTTP. This is my small script I’m using to make the call:

JavaScript

When I run this script, I get a 403 error:

JavaScript

For reference, here is a picture of me making the same exact request with Postman, and it works:

Postman picture

Any ideas on what the problem could be?

Edit:

Not sure if this is normal, but when I print out my request object that gets built, I see no indication that there are headers in the request:

JavaScript

Is what I get. Could this be part of the problem?

Edit2:

Nevermind, doing a

JavaScript

gives me what I originally put in:

JavaScript

Advertisement

Answer

So I figured out what my problem was. I’m not sure of the details behind it, but I should have been using my URL has https://api.genius.com/songs/378195/ instead of http://api.genius.com/songs/378195/

Postman seems fine with the http, but OkHttp needed https.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement