// Method(Private) #region SetPostInformation() - 게시할 정보를 구합니다. /// <summary> /// 게시할 정보를 구합니다. /// </summary> private PostInformation GetPostInformation() { PostInformation model = new PostInformation(); model.AccessToken = this.accessTokenTextBox.Text.Trim(); model.Header = "Bearer " + model.AccessToken; model.ApiURL = "https://openapi.naver.com/blog/writePost.json"; model.Title = this.titleTextBox.Text.Trim(); model.Category = this.categoryTextBox.Text.Trim(); model.Contents = this.contentsRichTextBox.Text.Trim(); model.Tag = this.tagTextBox.Text.Trim(); return(model); }
/// <summary> /// 요청을 생성합니다. /// </summary> private HttpWebRequest CreateRequest() { PostInformation model = GetPostInformation(); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(model.ApiURL); request.Headers.Add("X-Naver-Client-Id", clientID); request.Headers.Add("X-Naver-Client-Secret", clientSecret); request.Headers.Add("Authorization", model.Header); request.Method = "POST"; byte[] byteDataParams = Encoding.UTF8.GetBytes($"title={model.Title}&contents={model.Contents}"); request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = byteDataParams.Length; Stream stream = request.GetRequestStream(); stream.Write(byteDataParams, 0, byteDataParams.Length); stream.Close(); return(request); }