๐ฅ Javascript URL Encoding
๐ฅ Javascript URL Encoding
๋ฌธ์ ์ํฉ
โ
Frontend
์ฝ๋
1
const socket = new SockJS('http://localhost:8083/ws?token=' + username);
โ
Backend
์ฝ๋
1
2
3
4
5
6
7
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws")
.setAllowedOriginPatterns("*")
.setHandshakeHandler(customHandshakeHandler)
.withSockJS();
}
โ
Chrome
๊ฐ๋ฐ์ ๋๊ตฌ
WebSocket
์ฐ๊ฒฐ์ ์๋ํ์ง๋ง ์คํจํ๊ณ ์๋ค.- ์ฒ์์๋ ์ฝ๋๋ฅผ ์๋ฌด๋ฆฌ ๋ด๋ ๋ฌธ์ ๋ฅผ ์ฐพ์ง ๋ชปํ๋ค.
๋ฌธ์ ์์ธ
- ํ ํฐ์ผ๋ก ์ ๋ฌ๋๋ ๊ฐ์ด
??
๋ฌธ์์ด์ธ๋ฐ,URL
์ ํตํด ์ ๋ฌ๋๋ ๊ณต๋ฐฑ,=
,&
,?
,#
๊ฐ์ ํน์ ๋ฌธ์๋ค์URL
์์ ์์ฝ๋ ๋ฌธ์๋ก ์ ํ๋๋ฏ๋ก ์๋ํ ๋๋ก ์์ฒญ์ด ์ ๋ฌ๋์ง ์๋๋ค.
ํด๊ฒฐ ๋ฐฉ๋ฒ
1
const socket = new SockJS('http://localhost:8083/ws?token=' + encodeURIComponent(username));
Frontend
์์ ์์ฒญ ์ ์ ๋ฌํ๋Query String
์username
์Encoding
ํด์ผ ํ๋ค.
This post is licensed under CC BY 4.0 by the author.