RegressionSquirrel
RegressionSquirrel

Reputation: 472

HTTR GET works in browser, but fails in RStudio

Background:

I'm using the code below to get a zipped file containing some XML-documents. A note on reproducibility; the endpoint is IP-restricted as well, so you won't be able to request anything from it (it'll just time out).

GET("https://dpsv3.doffin.no/Doffin/notices/Download/2020-07-17",
    authenticate(user, passwd),
    accept = "application/zip")

Using this from R; I get a 403 Access denied. If I use the same in Postman, I get the file. If I go to https://dpsv3.doffin.no/Doffin/notices/Download/2020-07-17 in a browser, I get a user/pass prompt and once entered, I get the file.

Questions

Is there anything wrong with my code? From what I gather, it should work, and similar code work with other APIs. Using the same code towards the test environment works; and if I enter the wrong password for the test environment, I get a 401 error instead. From this I gather that the authenticate part of my call isn't processed at the endpoint, but I can't spot any errors here. Any input?

Upvotes: 0

Views: 1010

Answers (1)

RegressionSquirrel
RegressionSquirrel

Reputation: 472

Soo, I think I found the problem. Changing my code to the following works:

GET("https://dpsv3.doffin.no/Doffin/notices/Download/2020-07-21",
    authenticate(user, passwd),
    accept = "application/zip",
    user_agent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"))

I'm not sure why, but I guess there might be limitations on the endpoint? In either case; it works so I am happy.

Upvotes: 1

Related Questions