How do I restrict JSON access?

前端 未结 8 697
时光取名叫无心
时光取名叫无心 2020-11-30 23:24

I have a web application that pulls data from my newly created JSON API.

My static HTML pages dynamically calls the JSON API via JavaScript from the static HTML page

8条回答
  •  自闭症患者
    2020-12-01 00:04

    I think you might be misunderstanding the part where the JSON request is initiated from the user's browser rather than from your own server. The static HTML page is delivered to the user's browser, then it turns around and executes the Javascript code on the page. This code opens a new connection back to your server to obtain the JSON data. From your PHP script's point of view, the JSON request comes from somewhere in the outside world.

    Given the above mechanism, there isn't much you can do to prevent anybody from calling the JSON API outside the context of your HTML page.

提交回复
热议问题