A → B 시스템으로 날리는 GET 요청에 있는 쿼리 파라미터에 암호문을 보내는 로직이 있었음

https://hello.com?userId=암호문

 

문제점 : B 시스템에서 userId에 있는 암호문을 제대로 받아들이지 못함

 

원인 : 암호문에 + 기호가 있었음 => HTTP URL에서 + 는 공백을 의미하는 예약 문자임 => A에서 의도한 내용과 다른 내용을  B가 받게 됨 (B서버는 + 를 공백으로 인식)

 

해결법

1) + 기호를 %2B로 바꿔서 보내면?

2) java.net.URLEencoder사용 ( URL Encoder.encoder("~~~~~") )

 

 


https://www.w3schools.com/tags/ref_urlencode.asp

URL Encoding (Percent Encoding)

URL encoding converts characters into a format that can be transmitted over the Internet.

URLs can only be sent over the Internet using the ASCII character-set.

Since URLs often contain characters outside the ASCII set(ex.한국어), the URL has to be converted into a valid ASCII format.

URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits.

URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20.

=> URL에서 사용할 수 없는 문자(예약문자, 한글 등)들을 사용할 수 있도록 Encode

space %20 %20
! %21 %21
" %22 %22
# %23 %23
$ %24 %24
% %25 %25
& %26 %26
' %27 %27
( %28 %28
) %29 %29
* %2A %2A
+ %2B %2B
, %2C %2C
- %2D %2D
. %2E %2E
/ %2F %2F

'WEB > http' 카테고리의 다른 글

[HTTP] HTTP  (0) 2021.06.14