Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sample/c#-asp.net/APIExamURL.cs 코드 에로 수정 요청. #19

Open
korykim opened this issue Feb 27, 2023 · 0 comments
Open

sample/c#-asp.net/APIExamURL.cs 코드 에로 수정 요청. #19

korykim opened this issue Feb 27, 2023 · 0 comments

Comments

@korykim
Copy link

korykim commented Feb 27, 2023

기존 샘플 코드 에로 발생. code 수정 요청.

string query = System.Web.HttpUtility.UrlEncode("https://developers.naver.com/notice", Encoding.UTF8) // 수정 내용

using System;
using System.Net;
using System.Text;
using System.IO;

namespace NaverAPI_Guide
{
    public class APIExamURL
    {
        static void Main(string[] args)
        {
            string url = "https://openapi.naver.com/v1/util/shorturl";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Headers.Add("X-Naver-Client-Id", "YOUR_CLIENT_ID"); // 개발자센터에서 발급받은 Client ID
            request.Headers.Add("X-Naver-Client-Secret", "YOUR_CLIENT_SECRET"); // 개발자센터에서 발급받은 Client Secret
            request.Method = "POST";
            //string query = "https://developers.naver.com/notice"; // 단축할 URL 대상
            string query = System.Web.HttpUtility.UrlEncode("https://developers.naver.com/notice", Encoding.UTF8) // 수정 내용
            byte[] byteDataParams = Encoding.UTF8.GetBytes("url=" + query);
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = byteDataParams.Length;
            Stream st = request.GetRequestStream();
            st.Write(byteDataParams, 0, byteDataParams.Length);
            st.Close();
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream stream = response.GetResponseStream();
            StreamReader reader = new StreamReader(stream, Encoding.UTF8);
            string text = reader.ReadToEnd();
            stream.Close();
            response.Close();
            reader.Close();
            Console.WriteLine(text);
        }
    }
}
@korykim korykim changed the title sample/c#-asp.net/APIExamURL.cs 코트 에로 수정 요청. sample/c#-asp.net/APIExamURL.cs 코드 에로 수정 요청. Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant