WebClient
의 System.Net
네임 스페이스를 사용하여 프로그래밍 방식으로 URL을 실행할 수 있습니다. url은 url을로드하는 동안 추출 할 수있는 쿼리 문자열을 포함 할 수 있습니다. 그러면 응답은 string으로 디코딩 될 수 있으며 기본적으로 html로되어 있으므로 사용자의 편의에 따라 사용할 수 있습니다.
다음은 기능을 수행해야하는 방법입니다.
public static string ReadUrlToString(string url, string method, string postParams, string userName, string password, string domain)
{
var wc = new WebClient();
// set the user agent to IE6
wc.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705;)");
AssignCredentials(wc, userName, password, domain);
try
{
if (Is.EqualString(method, "POST"))
{
// Eg "field1=value1&field2=value2"
var bret = wc.UploadData(url, "POST", Encoding.UTF8.GetBytes(postParams));
return Encoding.UTF8.GetString(bret);
}
// actually execute the GET request
return wc.DownloadString(url);
}
catch (WebException we)
{
// WebException.Status holds useful information
//throw as needed
}
catch (Exception ex)
{
// other errors
//throw as needed
}
}
방법은하기와 같다.
private static void AssignCredentials(WebClient wc, string userName, string password, string domain)
{
if (Is.NotEmptyString(userName))
{
wc.Credentials = Is.EmptyString(domain)
? new NetworkCredential(userName, password)
: new NetworkCredential(userName, password, domain);
}
}
희망이 있습니다.
"웹 스크래핑"또는 "스크린 스크래핑"을 찾으십시오. –
존, 미안해. – user3040784
HttpClient를 사용하여 HTTP 요청을 보내고 응답을받을 수 있습니다. 웹 브라우저의 디버거를 사용하여 어떤 요청과 응답이 전송되는지 파악하고 클라이언트와 모방하는 것이 좋습니다. –