A
A
Alexey Likhachev2014-03-18 23:26:55
JavaScript
Alexey Likhachev, 2014-03-18 23:26:55

Is it possible to send a POST request to api.direct.yandex from a client?

Actually, here is the description api.yandex.ru/direct/doc/concepts/JSON.xml , but is it possible to send a request from the client, without using the backend?

I do something like

var data = {
        "method": "GetClientInfo",
        "param": ["правильный_юзер"],
        "locale": "ru",
        "token": "правильный_токен"
      };
      $.ajax({
        type: "POST",
        url: "https://api.direct.yandex.ru/v4/json/",
        dataType: "jsonp",
        crossDomain: true,
        data: data
      });


But in the end I get the wrong answer. Tell me, in which direction to think, and is such an option possible?

When using the server and sending a request from it, everything works fine.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Cyril, 2014-03-20
@manny

most likely an API error like XMLHttpRequest cannot load https://api.direct.yandex.ru/v4/json/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'domain' is therefore not allowed access.

Well, here's your answer. Actually what I started with: the browser is blocking a cross-domain ajax request. In short: I don’t think it will be possible to force Yandex to give the desired header (Access-Control-Allow-Origin). Conclusion: no, it will not be possible to make an ajax request to the Yandex api from another domain.

A
Alexander Litvinov, 2014-03-18
@Sander_Li

Try Postman . Perhaps Yandex does not support Cross Site Authentication. I didn’t go into details, but you probably specified the domain for your application and thus tied to the api. Therefore, requests are only possible from that domain.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question