Intercepting image load request of the browser

后端 未结 3 883
萌比男神i
萌比男神i 2021-01-17 23:43

I would like to know if there is a way to intercept the image loading requests of a browser and add some request headers expected by the server.

The actual scenario

3条回答
  •  长发绾君心
    2021-01-18 00:10

    No, there is not a way to do that, and it's a very good thing too.

    (Well, there's no way to do it from your code. The browser owner can install a tool that alters requests if they so desire, of course.)

    The fact that browsers issue HTTP requests for scripts and images in their own strict ways means that a site using XHR can prevent some kinds of CSRF attacks (cross-site request forgery) by having the server refuse certain requests if they don't include a special header that the site's own XHR code adds.

    You can't control exactly what a browser does to the header with form posts, either.

提交回复
热议问题