eabet
V2EX  ›  问与答

WebSocket 请求能否自定义 Origin

  •  
  •   eabet · Jul 8, 2017 · 5749 views
    This topic created in 3278 days ago, the information mentioned may be changed or developed.

    使用 JS 创建 WEBSOCKET 连接, new WebSocket("ws://127.0.0.1:7326"); 能否自定义 Origin ?

    3 replies    2017-07-08 21:14:30 +08:00
    ghostheaven
        1
    ghostheaven  
       Jul 8, 2017 via Android
    不能,能的话就能随便跨域了。但服务端可以允许跨域,参见 Access-Control-Allow-Origin 头 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
    momocraft
        2
    momocraft  
       Jul 8, 2017
    Origin 是浏览器不能允许 js 改的 http 头之一.
    hxsf
        3
    hxsf  
       Jul 8, 2017   ❤️ 1
    事实上, 你都不能在 ws 连接上加任何 header
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1145 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 23:30 · PVG 07:30 · LAX 16:30 · JFK 19:30
    ♥ Do have faith in what you're doing.