반응형
[HttpGet]
public ActionResult GetCargoInfo(RtnFilesInfo value)
{
string str_crkyCn = value.crkyCn;
string str_cargMtNo = value.cargMtNo;
string str_mblNo = value.mblNo;
string str_hblNo = value.hblNo;
string str_blYy = value.blYy;

//화물관리번호 , BL 사용해서 했는지 확인 여부 필요.

	try
	{
		string url = "https://unipass.customs.go.kr:38010/ext/rest/cargCsclPrgsInfoQry/retrieveCargCsclPrgsInfo?crkyCn=i220k129u161i054w030p040s2&cargMtNo=00ANLU083N59007001";
		//uri = new Uri(url); // string 을 Uri 로 형변환
		string responseText = string.Empty;

		HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
		request.Method = "GET";

		using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())
		{
			HttpStatusCode status = resp.StatusCode;
			Console.WriteLine(status);  // 정상이면 "OK"


			Stream respStream = resp.GetResponseStream();
			using (StreamReader sr = new StreamReader(respStream))
			{
				responseText = sr.ReadToEnd();
				Console.WriteLine(responseText);
			}
		}
	}
	catch(Exception ex)
	{
		Console.WriteLine(ex.Message);
	}

	string sURL;
	sURL = "https://unipass.customs.go.kr:38010/ext/rest/cargCsclPrgsInfoQry/retrieveCargCsclPrgsInfo?crkyCn=i220k129u161i054w030p040s2&cargMtNo=00ANLU083N59007001";

	WebRequest wrGETURL;
	wrGETURL = WebRequest.Create(sURL);
	WebProxy myProxy = new WebProxy("myproxy", 80);

	myProxy.BypassProxyOnLocal = true;

	wrGETURL.Proxy = WebProxy.GetDefaultProxy();

	Stream objStream;
	objStream = wrGETURL.GetResponse().GetResponseStream();

	StreamReader objReader = new StreamReader(objStream);

	string sLine = "";
	int i = 0;
	string ReadingText = "";
	while (sLine != null)
	{
		i++;
		sLine = objReader.ReadLine();
		ReadingText += sLine;
		//if (sLine != null)
		//    Console.WriteLine("{0}:{1}", i, sLine);
	}
	//MessageBox.Show(ReadingText);
	//Console.WriteLine(ReadingText);
				//Console.ReadLine();
	System.Diagnostics.Debug.WriteLine(ReadingText);

	return this.Content(ReadingText, "text/xml");
}
반응형

[2020.04.23]
저는 유니패스에서 관세청 정보를 가져와서 사용하기 위해서 API를 확인하는 도중
유니패스 관세청 정보는 URL을 보내 XML로 데이터를 받는 방법으로 주기 때문에 XML을 텍스트로 가공하여 웹에 뿌려주는 로직을 만들기 위해서
아래와 같은 방법으로 C#에 코딩하여 사용 하였었습니다.

URL을 던져서 데이터를 받아와 XML를 한줄로 만드는 로직 입니다.

 

string sURL;
sURL = ""; //XML을 가져올 URL을 적어줍니다.
 
WebRequest wrGETURL;
wrGETURL = WebRequest.Create(sURL);

WebProxy myProxy = new WebProxy("myproxy", 80); //프록시 세팅
myProxy.BypassProxyOnLocal = true;
wrGETURL.Proxy = WebProxy.GetDefaultProxy();

Stream objStream;
objStream = wrGETURL.GetResponse().GetResponseStream();
StreamReader objReader = new StreamReader(objStream); //XML 데이터 가져오기

//XML 데이터 가져와서 string 한줄로 정리하는 로직
string sLine = "";
int i = 0;
string ReadingText = "";
while (sLine != null)
{
	i++;
	sLine = objReader.ReadLine();
	ReadingText += sLine;	
}

//제대로 XML이 생성 됐는지 확인 하는 명령어
System.Diagnostics.Debug.WriteLine(ReadingText);

return this.Content(ReadingText, "text/xml");

+ Recent posts