K
K
KarToSHKa_Ex2020-08-09 23:40:32
API
KarToSHKa_Ex, 2020-08-09 23:40:32

How to get a response from the Kinopoisk server?

I want to write a movie search application. I found the Kinopoisk api, but I don’t really understand how to get a response from the server and how to display any information. The documentation site says

curl -X GET "https://kinopoiskapiunofficial.tech/api/v2.1/films/300" -H "accept: application/json" -H "X-API-KEY: 71c5dd47-2ab2-40d4-bb00-4974097af5b6"

In my code I write
var key = "71c5dd47-2ab2-40d4-bb00-4974097af5b6";
            var request = WebRequest.Create("https://kinopoiskapiunofficial.tech/api/v2.1/films/300");
            request.ContentType = "application/json";
            request.Headers["X-API-KEY"] =  key;
            request.Method = "POST";
            textBox1.Text = Convert.ToString(request.GetResponse());

But when I try to display something, I get a 403 error. It looks like I can't log in to the site with a token and send a request, because when I try to enter a URL in the browser, I get a 401 Unauthorized error. I don’t really understand what I’m doing wrong, so I’m asking for help or maybe there are some articles about this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twobomb, 2020-08-10
@twobomb

Change method to get

var key = "71c5dd47-2ab2-40d4-bb00-4974097af5b6";
            var request = WebRequest.Create("https://kinopoiskapiunofficial.tech/api/v2.1/films/300");
            request.ContentType = "application/json";
            request.Headers["X-API-KEY"] = key;
            request.Method = "GET";
            using (var stream  = request.GetResponse().GetResponseStream()){
                List<byte> buff = new List<byte>();
                while (true){
                    int b = stream.ReadByte();
                    if(b != -1)
                        buff.Add((byte) b);
                    else
                        break;
                }
              textBox1.Text = Encoding.UTF8.GetString(buff.ToArray());
            }

or
using (var stream = new StreamReader(request.GetResponse().GetResponseStream()))
                 textBox1.Text = = stream.ReadToEnd();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question