Https://dapi.kakao.com/v2/local/search/address.json?query=서울 서초구 사용시 401에러 원인이 어떻게 되느지요 ?

키 : 2e3xxxxxxxxxxxxxxxxxx******
AppId: 335178

async onSearchJuso(cmd) {

  let URL1 = 'https://dapi.kakao.com/v2/local/search/address.json?query=서울 서초구';

  let params1 = {
  };
  let config1 = {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'Authorization': 'KakaoAK ' + '2e347xxxxxxxxxxxxxxxxxxxxxxxxxx'
    }
  };
  axios.defaults.withCredentials = false;
  let response1 = await axios.get(URL1, { params: params1 }, config1);

  console.log(response1);

}

  1. response

{“errorType”:“AccessDeniedError”,“message”:“cannot find Authorization : KakaoAK header”}

  1. 상태값

Request URL: https://dapi.kakao.com/v2/local/search/address.json?query=서울%20서초구
Request Method: GET
Status Code: 401 Unauthorized
Remote Address: 203.217.239.16:443
Referrer Policy: strict-origin-when-cross-origin
Access-Control-Allow-Headers: Authorization, KA, Origin, X-Requested-With, Content-Type, Accept
Access-Control-Allow-Methods: GET, OPTIONS
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Type: application/json;charset=UTF-8
Date: Mon, 09 Nov 2020 07:57:30 GMT
Server: nginx
Transfer-Encoding: chunked
X-Request-Id: 377a0dd0-2261-11eb-b041-492da67ee468
Accept: application/json, text/plain, /
Accept-Encoding: gzip, deflate, br
Accept-Language: ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7
Connection: keep-alive
Host: dapi.kakao.com
Origin: http://localhost:3000
Referer: http://localhost:3000/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: cross-site
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36
query: 서울 서초구

response body를 한번 살펴보시면 원인을 같이 응답 주고 있어요. body를 한번 출력해 보시겠어요?
로그를 대략 살펴보았는데, 요청한곳의 domain 등록이 제대로 되지 않은 케이스가 아닌가 추정됩니다.

PS) 해당 앱의 앱 아이콘과 이름을 좀 더 상세히 해주시면 좋을것 같아요.

키와 연결된 도메인 내용입니다.

1.https://evci.duckdns.org에서 작업한 log 입니다.

 'Authorization': 'KakaoAK ' + '2e3471exxxxxxxxxxxxxx******'

위의 내용이 전달이 되지 않는 현상입니다.

혹시 asyn와 await 때문이지요 ?

Request URL: https://dapi.kakao.com/v2/local/search/address.json?query=서울%20서초구
Request Method: GET
Status Code: 401 Unauthorized
Remote Address: 203.217.239.16:443
Referrer Policy: strict-origin-when-cross-origin
Access-Control-Allow-Headers: Authorization, KA, Origin, X-Requested-With, Content-Type, Accept
Access-Control-Allow-Methods: GET, OPTIONS
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Type: application/json;charset=UTF-8
Date: Tue, 10 Nov 2020 01:51:03 GMT
Server: nginx
Transfer-Encoding: chunked
X-Request-Id: 30f744f0-22f7-11eb-9d26-e53626908110
Accept: application/json, text/plain, /
Accept-Encoding: gzip, deflate, br
Accept-Language: ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7
Connection: keep-alive
Host: dapi.kakao.com
Origin: https://evci.duckdns.org
Referer: https://evci.duckdns.org/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: cross-site
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.193 Safari/537.36
query: 서울 서초구

좀 더 살펴보겠습니다!

해결을 했습니다.

다른 분을 위해서 적어 놓습니다.

axios와 dapi.kakao.com/v2/local/search/address.json에 대한 header 설정은

  axios.defaults.withCredentials = false;
  axios.defaults.headers.common['Authorization'] = 'KakaoAK ' + 'xxxxxxxxxxxxxxxxxxxxxxx';
  axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';

위와 같이 해야 401에러가 나지 않습니다.
header 정보가 세팅이 되지 않아서 발생한 문제입니다.

let URL = "https://dapi.kakao.com/v2/local/search/address.json?query=독립문공원길17";
  let params = {};
  let config1 = {};
  axios.defaults.withCredentials = false;
  axios.defaults.headers.common['Authorization'] = 'KakaoAK ' + 'xxxxxxxxxxxxxxxxxxxxxxx';
  axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
  axios.get(URL, { params: params }, config1)
    .then(function (response) {
      console.log("response : ", response.data.documents);
    })
    .catch(function (error) {
      console.log(error.response.headers);
    })
    .finally(function () {
      console.log("finally ");
    });
좋아요 3