반응형
조금더 진행해보자.
파싱이라는 용어를 사용하지만, 그냥 문자열 추출, 문자열 분리 정도로 이해 하면 된다.
일단 클라이언트가 요청하는 문장은 아래와 같다.
사용자의 웹브라우저 종류, 아이피, 요청페이지, 기타 등등 이라고 보면 된다.
요즘 핸드폰에서는 좀 더 많은 정보를 제공하는것 같지만,
일단 비전공자라 넘어가자
내가 찾고 싶은 문장은 page1.html, page2.html 이다.
사실 파싱에 대해서 정답은 없지만, 나라면 이렇게 하겠다. 이정도다.
꼭 이것이 좋은 방법이라고는 모르겠다.
나는 ":" 콜론을 기준점으로 두고 문장을 찾았다. 그리고 Referer: 라는 단어를 중심으로 찾았다.
원하는 글자를 찾으면 1과 2를 넘겨주는 함수를 만들었다.
new client
Host: 192.168.5.177
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36
Accept: image/webp,image/apng,image/*,*/*;q=0.8
Referer: http://192.168.5.177/page1.html
Accept-Encoding: gzip, deflate
Accept-Language: ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
int msg_parsing(char* str)
{
int nothing = 0;
char*p =str;
if( str==NULL || strlen(str)==0) return nothing;
while(*str!='\r' && *str!='\n' && *str!='\0' )
{
if(*str==':')
{
*str='\0';
if(strcmp(p, "Referer")==0)
{
str++;
}
break;
}
else str++;
}
return nothing;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
'아두이노' 카테고리의 다른 글
아두이노 이더넷 웹서버 만들기 -#13 (0) | 2020.05.04 |
---|---|
아두이노 이더넷 웹서버 만들기 -#12 (0) | 2020.05.03 |
아두이노 이더넷 웹서버 만들기 -#10 (0) | 2020.05.02 |
아두이노 이더넷 웹서버 만들기 -#9 (0) | 2020.05.01 |
아두이노 이더넷 웹서버 만들기 -#8 (0) | 2020.05.01 |
댓글