본문 바로가기

컴퓨터/클라이언트

HTTP GET 방식으로 서버에 요청하기 (작성중)

클라이언트에서 서버로 다음 정보를 보내며 요청한다고 가정하자.

{
  user: "sayyesdoit",
  age: 30
}

I. 쿼리스트링으로 정보를 보내며 요청하기

1. 브라우저 사용하기

2022.01.26 - [컴퓨터/클라이언트] - URI와 URL의 개념

 

URI와 URL의 개념

1. URI(Uniform resource Identifier) 주소 + 전달값 예) http://www.example.co.kr/?name=홍길동 2. URL(Uniform Resource Locator) 주소 예) http://www.example.co.kr/ ※ 그래서 URI가 URL을 포함하는 포함관..

bloghelloworld.tistory.com

1) 주소창에 URI 직접 입력

주소창에 다음과 같이 입력한다.

URL/?user=sayyesdoit&age=30

2) HTML form 으로 요청

HTML에 다음과 같이 코드를 입력하고 실행한다. 입력창에 값을 입력하여 요청한다.

<form action="URL주소" method="GET">
  <input type="text" name="user" />
  <input type="number" name="age" />
  <input type="submit" />
</form>

3) Javascript로 URI를 변경하여 요청

HTML

<input type="text" name="user" />
<input type="number" name="age" />
<button onclick="fnInfo">클릭</button>

Javascript

function fnInfo() {
  let user=document.getElementById("user").value;
  let age=document.getElementById("age").value;
  location.href=`URL주소/?user=${user}&age=${age}`;
}

※ 「`」는 작은 따옴표가 아닌 물결표시 밑의 Grave라는 따옴표이다.

4) Javascript fetch() API로 요청하고 응답받기

2022.01.27 - [컴퓨터/클라이언트] - fetch() 함수로 원격 API 호출하기

 

fetch() 함수로 원격 API 호출하기

※ 인터넷 익스플로러에서는 fetch() 함수를지원하지 않는다. 기본문법 fetch(url, options) .then((response) => console.log("response:", response)) .catch((error) => console.log("error:", error)); 1. GET..

bloghelloworld.tistory.com

2. 콘솔 사용하기

1) curl 사용하기