728x90
반응형
728x170
▶ POST 요청 이미지 구하기 예제
using System.Collections.Specialized;
using System.Drawing;
using System.Text;
using System.Web;
NameValueCollection collection = HttpUtility.ParseQueryString(string.Empty);
collection["ImageFilePath"] = "test.jpg";
string url = "http://localhost:9999/test.action";
string contentType = "application/x-www-form-urlencoded; charset=unicode";
Encoding encoding = Encoding.Unicode;
string argument = collection.ToString();
Image image = GetPOSTRequestImage(url, contentType, encoding, argument);
728x90
▶ POST 요청 이미지 구하기
using System.Drawing;
using System.IO;
using System.Net;
using System.Text;
#region POST 요청 이미지 구하기 - GetPOSTRequestImage(url, contentType, encoding, argument)
/// <summary>
/// POST 요청 이미지 구하기
/// </summary>
/// <param name="url">URL</param>
/// <param name="contentType">컨텐츠 타입</param>
/// <param name="encoding">인코딩</param>
/// <param name="argument">인자 문자열</param>
/// <returns>POST 요청 이미지</returns>
public Image GetPOSTRequestImage(string url, string contentType, Encoding encoding, string argument)
{
using(Stream stream = GetPOSTRequestStream(url, contentType, encoding, argument))
{
Image image = Bitmap.FromStream(stream);
return image;
}
}
#endregion
#region POST 요청 스트림 구하기 - GetPOSTRequestStream(url, contentType, encoding, argument)
/// <summary>
/// POST 요청 스트림 구하기
/// </summary>
/// <param name="url">URL</param>
/// <param name="contentType">컨텐츠 타입</param>
/// <param name="encoding">인코딩</param>
/// <param name="argument">인자 문자열</param>
/// <returns>POST 요청 스트림</returns>
public Stream GetPOSTRequestStream(string url, string contentType, Encoding encoding, string argument)
{
byte[] contentArray = encoding.GetBytes(argument);
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.ProtocolVersion = HttpVersion.Version11;
request.AllowAutoRedirect = true;
request.AllowWriteStreamBuffering = true;
request.Method = WebRequestMethods.Http.Post;
request.ContentType = contentType;
request.ContentLength = contentArray.Length;
using(Stream requestStream = request.GetRequestStream())
{
requestStream.Write(contentArray, 0, contentArray.Length);
}
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream responseStream = response.GetResponseStream();
return responseStream;
}
#endregion
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] RSACryptoServiceProvider 클래스 : 비대칭키 암호화 사용하기 (0) | 2017.05.30 |
---|---|
[C#/COMMON] WebClient 클래스 : 파일 다운로드시 진행 상태 표시하기 (0) | 2017.05.27 |
[C#/COMMON] GET 요청 이미지 구하기 (0) | 2017.05.27 |
[C#/COMMON] GET 요청 문자열 구하기 (0) | 2017.05.27 |
[C#/COMMON] GET 요청 스트림 구하기 (0) | 2017.05.27 |
[C#/COMMON] POST 요청 문자열 구하기 (0) | 2017.05.27 |
[C#/COMMON] POST 요청 스트림 구하기 (0) | 2017.05.27 |
[C#/COMMON] Dns 클래스 : GetHostAddresses 정적 메소드를 사용해 호스트 IP 주소 배열 구하기 (0) | 2017.05.26 |
[C#/COMMON] Dns 클래스 : GetHostName 메소드를 사용해 로컬 컴퓨터명 구하기 (0) | 2017.05.26 |
[C#/COMMON] 사용자 정의 컨트롤 속성 정의시 어트리뷰트 사용하기 (0) | 2017.05.25 |
댓글을 달아 주세요