Skip to content

Instantly share code, notes, and snippets.

@NeedPainkiller
Last active January 2, 2019 06:11
Show Gist options
  • Save NeedPainkiller/cae055cec5d37773de659dfa27e0f7e5 to your computer and use it in GitHub Desktop.
Save NeedPainkiller/cae055cec5d37773de659dfa27e0f7e5 to your computer and use it in GitHub Desktop.
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
// dotnet run .\Program.cs 3051577349 8995800075 8996300123 8997600079 8997700057 1010540144 1010863774 1011127195 1011230533 1011268892 1011275340 1011652137 1012151049 1020361041 1021551153
// dotnet publish -c Release -f netcoreapp2.1 -r win10-x64
namespace CRN_Dotnet
{
class CRNRequest
{
private static CrnWeb crnWeb = new CrnWeb();
static void Main(string[] args)
{
StringBuilder result = new StringBuilder("");
int index = 0;
foreach(String arg in args){
if(index == 0) {
index++;
continue;
}
result.Append(call(arg));
result.AppendLine();
index++;
}
Console.WriteLine(result.ToString());
}
private static String call(String crn){
String result = crnWeb.postCRN(crn);
result = result.Replace("\n","").Replace("\t"," ");
return crn + "\t" + result;
}
}
class CrnWeb{
private readonly String postUrl = "https://teht.hometax.go.kr/wqAction.do?actionId=ATTABZAA001R08&screenId=UTEABAAA13&popupYn=false&realScreenId=";
private String xmlRaw = "<map id=\"ATTABZAA001R08\"><pubcUserNo/><mobYn>N</mobYn><inqrTrgtClCd>1</inqrTrgtClCd><txprDscmNo>{CRN}</txprDscmNo><dongCode>15</dongCode><psbSearch>Y</psbSearch><map id=\"userReqInfoVO\"/></map>";
public String postCRN(String crn)
{
byte[] contents = System.Text.Encoding.ASCII.GetBytes(xmlRaw.Replace("{CRN}", crn));
HttpWebRequest request = createHttpWebRequest();
setContentStream(request, contents);
HttpWebResponse response;
response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream responseStream = response.GetResponseStream();
String resString = new StreamReader(responseStream).ReadToEnd();
responseStream.Close();
response.Close();
return getCRNresultFromXml(resString);
}
response.Close();
return "???";
}
private HttpWebRequest createHttpWebRequest()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(postUrl);
request.ContentType = "text/xml; encoding='utf-8'";
request.Method = "POST";
return request;
}
private void setContentStream(HttpWebRequest request, byte[] contents)
{
request.ContentLength = contents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(contents, 0, contents.Length);
requestStream.Close();
}
private String getCRNresultFromXml(String xmlData)
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xmlData);
String crnResult = xmlDocument.SelectNodes("//trtCntn").Item(0).InnerText;
return crnResult;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment