You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
3.7 KiB
99 lines
3.7 KiB
using Common.Helper;
|
|
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
|
|
namespace Common.Model.PowerCall
|
|
{
|
|
public class PowerCallPostGet
|
|
{
|
|
private readonly string powerCallURL = ApplicationConfig.ReadWebConfig("POWERCALL_URL", "");
|
|
|
|
public string GetFromPowerCAll(string _url, string _token = null)
|
|
{
|
|
try
|
|
{
|
|
//Trace.Assert(_token != null && !_url.Contains("oauth"));
|
|
HttpWebRequest powerCallRequest = null;
|
|
powerCallRequest = (HttpWebRequest)HttpWebRequest.Create(powerCallURL + _url);
|
|
powerCallRequest.Method = "GET";
|
|
//파워콜 최대 TimeOut
|
|
// TODO replace value from stored login scope access token
|
|
if (_token != null && !_url.Contains("oauth"))
|
|
{
|
|
powerCallRequest.Headers.Add("Authorization", "Bearer " + _token);
|
|
powerCallRequest.Accept = "application/json";
|
|
}
|
|
//else default
|
|
|
|
using (HttpWebResponse powerCallResponse = (HttpWebResponse)powerCallRequest.GetResponse())
|
|
{
|
|
Stream respStream = powerCallResponse.GetResponseStream();
|
|
StreamReader reader = new StreamReader(respStream, Encoding.GetEncoding("UTF-8"), true);
|
|
|
|
return reader.ReadToEnd();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
return string.Empty;
|
|
}
|
|
|
|
public string PostToPowerCall(string _url, string _token = null, string _jsonData = null)
|
|
{
|
|
try
|
|
{
|
|
//Trace.Assert(_token != null);
|
|
|
|
HttpWebRequest kftcRequest = (HttpWebRequest)HttpWebRequest.Create(powerCallURL + _url);
|
|
kftcRequest.Method = "POST";
|
|
//Authorization 헤더를 보낼지 여부를 설정
|
|
kftcRequest.PreAuthenticate = true;
|
|
kftcRequest.ContentType = "application/json";
|
|
|
|
// TODO replace value from stored login scope access token
|
|
if (_token == null)
|
|
{
|
|
//case of get token in oauth
|
|
kftcRequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
|
|
|
|
byte[] bytes = Encoding.UTF8.GetBytes(_jsonData);
|
|
kftcRequest.ContentLength = bytes.Length;
|
|
|
|
using (Stream requestStream = kftcRequest.GetRequestStream())
|
|
{
|
|
requestStream.Write(bytes, 0, bytes.Count());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
kftcRequest.Headers.Add("Authorization", "Bearer " + _token);
|
|
kftcRequest.Accept = "application/json";
|
|
|
|
byte[] bytes = Encoding.UTF8.GetBytes(_jsonData);
|
|
kftcRequest.ContentLength = bytes.Length;
|
|
|
|
using (Stream requestStream = kftcRequest.GetRequestStream())
|
|
{
|
|
requestStream.Write(bytes, 0, bytes.Count());
|
|
}
|
|
}
|
|
|
|
using (HttpWebResponse kftcResponse = (HttpWebResponse)kftcRequest.GetResponse())
|
|
{
|
|
Stream respStream = kftcResponse.GetResponseStream();
|
|
StreamReader reader = new StreamReader(respStream, Encoding.GetEncoding("UTF-8"), true);
|
|
|
|
return reader.ReadToEnd();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
return string.Empty;
|
|
}
|
|
}
|
|
}
|