I have successfully made many requests in the past, but usually to my own web server. I am stuck on this one. The request works fine in Postman, but in my Go code, the server returns an error 400 code. I wish the response could give me a clue on what I need to change.
In Postman, I have set the host to: https://finnhub.io/api/v1
and then added : /stock/candle. to the URL line and set it to ‘get’. I have set the params and the URL then shows: {{host}}/stock/candle?symbol=msft&resolution=D&from=1649887189&to=1658527189
The authorization is set in the collection as:
Key: X-Finnhub-Token
Value: c362xxxxxxxxxuojg (modified for security)
I do a send and it performs as requested. I get a list of stock candles. Nice
However, when I attempt this in Go, I get an error 400.
I have not figured out why I get an error code 400. However, I have downloaded Finnhub’s GO SDK and it can retrieve the data just fine. It’s a very complex project and the access is very high-level and I haven’t yet found exactly where they are executing the request. I guess I’ll use the SDK. I would still like to know why I can use the request in Postman but not as a simple request in Go.
What is the response from the server? Something like dump, err := httputil.DumpResponse
You said it was empty, but you may find a clue if you can get a response from the server. The server must response in some way. I have played a bit with API in AJAX and had a fair share of CORS errors.
I just ran the offending code again to check the dump response. This time it succeeded with status 200. And I didn’t change the code. Pretty strange, but I need to move on. I’ll use the SDK as it works just fine every time.
Thanks for your responses.
Interesting.
The code will send the same request every time, except for the lines
which changes on every run. (Also the from param).
Could there be some values that the server objects to?
e.g. will it object to values of to in the future?
Could this be a problem of clock-skew between client and server?
What happens if you ommit the to= term in the request?