개발환경 C# winforms 입니다.
1.웹뷰로 해서 https://kauth.kakao.com/oauth/authorize로 code는 가져왓습니다.
2.그런다음 api로 https://kauth.kakao.com를 호출하였습니다.
var client = new RestClient("https://kauth.kakao.com");
var request = new RestRequest("oauth/token/", Method.POST);
request.AddParameter("grant_type", "authorization_code");
request.AddParameter("client_id", "----");
request.AddParameter("redirect_uri", "http://localhost/oauth");
request.AddParameter("code", code);
request.AddHeader("Content-type", "application/x-www-form-urlencoded");
request.AddHeader("charset", "utf-8");
request.AddHeader("Connection", "Keep-Alive");
request.AddHeader("User-Agent", "RestSharp");
IRestResponse response = client.Execute(request);
var content = response.Content;
Console.WriteLine(content);
서버가 무언가 잘못된것 같네요. 수정이 필요할듯 합니다.
"{\"status\":-500,\"message\":\"An unexpected error has occurred. The error may have been caused by temporary errors in the server or in the network connection. The Kakao Team is working to solve the problem.\"}"
아래는 curl 호출 결과 입니다.
curl -v -X POST https://kauth.kakao.com/oauth/token \
> -d 'grant_type=authorization_code' \
> -d 'client_id=---' \
> -d 'redirect_uri=http://localhost/oauth' \
> -d 'code=---'
* Hostname was NOT found in DNS cache
* Trying 203.133.166.32...
* Connected to kauth.kakao.com (203.133.166.32) port 443 (#0)
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using ECDHE-RSA-AES128-SHA256
* Server certificate:
* subject: C=KR; ST=Jeju-do; L=Jeju-si; O=Kakao Corp.; CN=*.kakao.com
* start date: 2018-07-09 00:00:00 GMT
* expire date: 2020-10-08 12:00:00 GMT
* subjectAltName: kauth.kakao.com matched
* issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=Thawte TLS RSA CA G1
* SSL certificate verify ok.
> POST /oauth/token HTTP/1.1
> User-Agent: curl/7.35.0
> Host: kauth.kakao.com
> Accept: */*
> Content-Length: 200
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 200 out of 200 bytes
< HTTP/1.1 200 OK
< Date: Fri, 02 Nov 2018 11:26:06 GMT
< Content-Type: application/json;charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-XSS-Protection: 1; mode=block
< X-Frame-Options: DENY
< X-Content-Type-Options: nosniff
< Kakao: Talk
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, POST, OPTIONS
< Access-Control-Allow-Headers: Authorization, KA, Origin, X-Requested-With, Content-Type, Accept
<
* Connection #0 to host kauth.kakao.com left intact
{"access_token":"---","token_type":"bearer","refresh_token":"---","expires_in":21599,"scope":"profile","refresh_token_expires_in":2591999}
3.restsharp이라는 라이브러리를 사용중입니다.
라이브러리에서 https 문제인것 같아서 https://jsonplaceholder.typicode.com/를 호출해봤습니다.
var client = new RestClient("https://jsonplaceholder.typicode.com/");
var request = new RestRequest("users/", Method.POST);
request.AddParameter("name", "value");
IRestResponse response = client.Execute(request);
var content = response.Content; // raw content as string
Console.WriteLine(content);
위의 결과는 아래와 같습니다. 정상적으로 https 통신이 이뤄집니다.
"{\n \"name\": \"value\",\n \"id\": 11\n}"