http 프로토콜-C#웹 소스 코드 가져오기
24188 단어 소스 코드http 프로토콜C#웹 페이지 가져오기
- http C#
-
- :
-
- using System.Text;
- using System.Net;
- private string getHtml(string url)
- {
- WebClient myWebClient = new WebClient();
- byte[] myDataBuffer = myWebClient.DownloadData (url);
- return Encoding.Default.GetString(myDataBuffer);
- }
-
- :
-
- public string getHttp(string HttpUrl,string RefererUrl)
- {
- string html = "";
- try
- {
- MSXML2.XMLHTTP Http = new MSXML2.XMLHTTPClass();
- xmlhttp.open("GET", Url, false, null, null);
- Http.open("GET",HttpUrl,false,null,null);
- Http.setRequestHeader("Referer",RefererUrl);
- //Http.setRequestHeader("Referer",RefererUrl);
- Http.setRequestHeader("Content-Type", "text/html;charset=gb2312");
- Http.send("");
- html = Encoding.Default.GetString((byte[])Http.responseBody);
- Http = null;
- }
- catch
- {
-
- }
- return html;
- }
-
-
-
-
-
- public bool getweb(string strURL,out string buf)
- {
- buf="";
- try
- {
- //Uri url=new Uri(strURL,false);
- HttpWebRequest request;
- request = (HttpWebRequest)WebRequest.Create(strURL);
- request.Method="POST"; //Post
- request.ContentType="text/html;charset=gb2312"; //
- string paraUrlCoded = System.Web.HttpUtility.UrlEncode(""); // URL
- byte[] payload;
- payload = System.Text.Encoding.GetEncoding("GB2312").GetBytes(paraUrlCoded); // URL
- request.ContentLength = payload.Length; // ContentLength
- Stream writer = request.GetRequestStream(); //
- writer.Write(payload,0,payload.Length); //
- writer.Close(); //
- HttpWebResponse response;
- response = (HttpWebResponse)request.GetResponse(); //
- Stream s;
- s = response.GetResponseStream();
- StreamReader objReader = new StreamReader(s,System.Text.Encoding.GetEncoding("GB2312"));
- string HTML = "";
- string sLine ="";
- int i = 0;
- while (sLine!=null)
- {
- i++;
- sLine = objReader.ReadLine();
- if (sLine!=null)
- HTML += sLine;
- }
- //HTMLHTML = HTML.Replace("<","<");
- //HTMLHTML = HTML.Replace(">",">");
- buf=HTML;
- return true;
- }
- catch (Exception x)
- {
- buf=x.Message.ToString();
- return false;
- }
- }
-
- Cookie:
- CookieContainer cc = new CookieContainer();
- public bool getweb(string strURL,out string buf)
- {
- buf="";
- try
- {
- HttpWebRequest request;
- request = (HttpWebRequest)WebRequest.Create(strURL);
- request.Method="POST"; //Post
- request.ContentType="text/html;charset=gb2312"; //
- string paraUrlCoded = System.Web.HttpUtility.UrlEncode(""); // URL
- byte[] payload;
- payload = System.Text.Encoding.GetEncoding("GB2312").GetBytes(paraUrlCoded); // URL
- request.ContentLength = payload.Length; // ContentLength
- Stream writer = request.GetRequestStream(); //
- writer.Write(payload,0,payload.Length); //
- writer.Close(); //
- HttpWebResponse response;
- response = (HttpWebResponse)request.GetResponse(); //
- Stream s;
- s = response.GetResponseStream();
- StreamReader objReader = new StreamReader(s,System.Text.Encoding.GetEncoding("GB2312"));
- string HTML = "";
- string sLine ="";
- int i = 0;
- while (sLine!=null)
- {
- i++;
- sLine = objReader.ReadLine();
- if (sLine!=null)
- HTML += sLine;
- }
-
- buf=HTML;
- return true;
- }
- catch (Exception x)
- {
- buf=x.Message.ToString();
- return false;
- }
- }
- public bool getweb(string strURL,out string buf,string postData)
- {
- buf="";
- try
- {
-
- ASCIIEncoding encoding = new ASCIIEncoding();
- byte[] data = encoding.GetBytes(postData);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL);
- request.Method = "POST";
- request.ContentType = "application/x-www-form-urlencoded";
- request.ContentLength = data.Length;
- Stream newStream = request.GetRequestStream();
- newStream.Write(data, 0, data.Length);
- newStream.Close();
-
- request.CookieContainer = cc;
-
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- cc.Add(response.Cookies);
- Stream stream = response.GetResponseStream();
- string sHtml = new StreamReader(stream, System.Text.Encoding.Default).ReadToEnd();
- buf=sHtml;
- return true;
- }
- catch (Exception x)
- {
- buf=x.Message.ToString();
- return false;
- }
- }
-
- private string getWebresourceFile1(string url)
- {
-
- WebClient myWebClient = new WebClient();
- byte[] myDataBuffer = myWebClient.DownloadData(url);
- string SourceCode = Encoding.Default.GetString(myDataBuffer);
- saveSourceCode(SourceCode);
- return SourceCode;
- }
-
- 2
- private string getWebresourceFile2(string url)
- {
- HttpWebRequest request=(HttpWebRequest)WebRequest.Create(url);
- HttpWebResponse response=(HttpWebResponse)request.GetResponse();
- request.Method = "GET ";
- Stream receiveStream=response.GetResponseStream();
- StreamReader readStream=new StreamReader(receiveStream,Encoding.Default);
- string SourceCode=readStream.ReadToEnd();
- saveSourceCode(SourceCode);
- response.Close();
- readStream.Close();
- return SourceCode;
-
- }
- 3
- private string getWebresourceFile3(string url)
- {
- WebClient wc = new WebClient();
- wc.Credentials = CredentialCache.DefaultCredentials;
- Byte[] pageData = wc.DownloadData(url);
- string SourceCode = Encoding.Default.GetString(pageData);
- saveSourceCode(SourceCode);
- wc.Dispose();
- return SourceCode;
- }
-
- 4
- private string getWebresourceFile4(string url)
- {
- WebClient wc = new WebClient();
- wc.Credentials = CredentialCache.DefaultCredentials;
- Stream resStream = wc.OpenRead(url);
- StreamReader sr = new StreamReader(resStream,System.Text.Encoding.Default);
-
- string SourceCode = sr.ReadToEnd();
- saveSourceCode(SourceCode);
- resStream.Close();
- wc.Dispose();
- return SourceCode;
- }
- 5
- private string getWebresourceFile5(string url)
- {
- WebRequest request = WebRequest.Create(url);
- WebResponse response = request.GetResponse();
- Stream resStream = response.GetResponseStream();
- StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
- string SourceCode = sr.ReadToEnd();
- saveSourceCode(SourceCode);
- resStream.Close();
- sr.Close();
- return SourceCode;
- }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
JAVA- 소스 코드 분할(Package 사용)▪️test45.java 소스 코드 ▪️test47.java 소스 코드 ▪️실행 결과 더하면 12, 당기면 8 ▪️예① 클래스 이름에 대한 완전한 입력 생략 import 문 사용 ▪️예① test45.java 소스 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.