'Problems trying to execute a POST request of an .ashx URL

Hi everybody and thanks in advance for taking the time to read my question.

This is my scenario:

I have an URL that gives me a JSON response when executed.

https://servicio.mapa.gob.es/reto/JSon/Entidad.ashx?accion=[action]&nif=[ID]&fecha=[date]&operacion=[operation_code]

This URL has some parameters, and when I navigate to it, the body of the website that I get is a JSON file where all the information is located.

So far so good.

Now, I want to insert this information into my VB.NET project, and manipulate this data.

The problem is that I had to inspect source code of the website to find that URL, and this website requires authentication. So when I execute a POST request with this URL from my VB.NET project, the response I get from the URL is a login page, instead of the response that I get when I do it into my web browser once logged in.

I have tried using REST Client and Web Client with different kind of authentication methods, but none of them have given me any result.

I have found some information online related with the cookies of the site, but I can't manage to do anything useful.

Is there any way of creating a "context" or "session" or something like that in which I could authenticate myself and be able to execute the POST Request within those credentials?

Could I get any light on the cookies matter if that is the way of doing it?

Thank you very much!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source