eabet
V2EX  ›  问与答

WebSocket 请求能否自定义 Origin

  •  
  •   eabet · Jul 8, 2017 · 5760 views
    This topic created in 3282 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   ·   2480 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 16:01 · PVG 00:01 · LAX 09:01 · JFK 12:01
    ♥ Do have faith in what you're doing.