# HttpServletRequest - 기본 사용법

HttpServletRequest가 제공하는 기본 기능들을 통해 헤더의 start-line를 포함한 모든 정보와 기타정보(HTTP 메시지는 아니지만 네트워크 연결 정보, 내 서버 정보 등) 을 알 수 있다

start-line 정보

1. request.getMethod() : GET
2. request.getProtocol() : HTTP/1.1
3. request.getScheme() : <http://localhost:8080/request-header>
4. request.getRequestURL() : /request-test
5. request.getRequestURI() : username=hi
6. rquest.getQueryString() : 쿼리 정보
7. request.isSecure() : https 사용유무

헤더 정보\
request.getHeaderNames()의 asIterator().forEachReamaining() 반복문 같은 개념! 으로 헤더의 모든 정보들을 조회할 수 있다!

```java
request.getHeaderNames().asIterator().forEachRemaining(headerName -> System.out.println(headerName + ":" + request.getHeader(headerName)));
```

헤더 편리한 조회

1. request.getServerName() : Host 헤더
2. request.getServerPort() : Host 헤더
3. request.getLocale() : 클라이언트가 선호하는 언어설정 보여준다
4. request.getCookies() : 쿠키 조회
5. request.getContentType() : Content 편의 조회 //Postman으로 테스트해봄
6. request.getContentLength() : Content 길이
7. request.getContentType() : Content Type 조회
8. request.getCharacteerEncoding() : 인코딩 정보

기타 정보\
HTTP 메시지의 정보는 아니다.

1. request.getRemoteHost()
2. request.getRemoteAddr()
3. request.getRemotePort()
4. request.getLocalName()
5. request.geetLocalAddr()
6. request.getLocalPort()

기타 정보 조회 실행 결과

![](/files/-Mduf5ONLsSihLcX0o0A)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://heunnajo.gitbook.io/mvc/undefined-1/httpservletrequest-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
