Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 202 additions & 0 deletions code.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
using System;
using System.IO;
using System.Net;
using System.Text;
// ����https
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
// end����https


namespace NT_MiddleDataService.ADO
{
public enum HttpVerbNew
{
GET, //method ���õľ��⼸������������������ get����ȡ post���޸� put��д�� delete��ɾ��
POST,
PUT,
DELETE
}


public class ContentType//����Postman��������������
{
public string Text = "text/plain";
public string JSON = "application/json";
public string Javascript = "application/javascript";
public string XML = "application/xml";
public string TextXML = "text/xml";
public string HTML = "text/html";
}


public class RestApiClient
{
public string EndPoint { get; set; } //�����url��ַ
public HttpVerbNew Method { get; set; } //������
public string ContentType { get; set; } //��ʽ����
public string PostData { get; set; } //���͵�����


public RestApiClient()
{
EndPoint = "";
Method = HttpVerbNew.GET;
ContentType = "text/xml";
PostData = "";
}
public RestApiClient(string endpoint, string contentType)
{
EndPoint = endpoint;
Method = HttpVerbNew.GET;
ContentType = contentType;
PostData = "";
}
public RestApiClient(string endpoint, HttpVerbNew method, string contentType)
{
EndPoint = endpoint;
Method = method;
ContentType = contentType;
PostData = "";
}


public RestApiClient(string endpoint, HttpVerbNew method, string contentType, string postData)
{
EndPoint = endpoint;
Method = method;
ContentType = contentType;
PostData = postData;
}


// ����https
private static readonly string DefaultUserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";


private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true; //���ǽ���
}
// end����https


public string MakeRequest()
{
return MakeRequest("");
}


public string MakeRequest(string parameters)
{
var request = (HttpWebRequest)WebRequest.Create(EndPoint + parameters);


// ����https
if (EndPoint.Substring(0, 8) == "https://")
{
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
}
// end����https


request.Method = Method.ToString();
request.ContentLength = 0;
request.ContentType = ContentType;


if (!string.IsNullOrEmpty(PostData) && Method == HttpVerbNew.POST)//������͵����ݲ�Ϊ�գ����ҷ�����post
{
var encoding = new UTF8Encoding();
var bytes = Encoding.GetEncoding("iso-8859-1").GetBytes(PostData);//���뷽ʽ���Լ�������и��ģ�������Ŀ��ʹ�õ���UTF-8
request.ContentLength = bytes.Length;


using (var writeStream = request.GetRequestStream())
{
writeStream.Write(bytes, 0, bytes.Length);
}
}


if (!string.IsNullOrEmpty(PostData) && Method == HttpVerbNew.PUT)//������͵����ݲ�Ϊ�գ����ҷ�����put
{
var encoding = new UTF8Encoding();
var bytes = Encoding.GetEncoding("iso-8859-1").GetBytes(PostData);//���뷽ʽ���Լ�������и��ģ�������Ŀ��ʹ�õ���UTF-8
request.ContentLength = bytes.Length;


using (var writeStream = request.GetRequestStream())
{
writeStream.Write(bytes, 0, bytes.Length);
}
}
using (var response = (HttpWebResponse)request.GetResponse())
{
var responseValue = string.Empty;


if (response.StatusCode != HttpStatusCode.OK)
{
var message = String.Format("Request failed. Received HTTP {0}", response.StatusCode);
throw new ApplicationException(message);
}


// grab the response
using (var responseStream = response.GetResponseStream())
{
if (responseStream != null)
using (var reader = new StreamReader(responseStream))
{
responseValue = reader.ReadToEnd();
}
}


return responseValue;
}
}


public bool CheckUrl(string parameters)
{
bool bResult = true;


HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(EndPoint + parameters);
myRequest.Method = Method.ToString(); //�����ύ��ʽ����Ϊ����������������䣢��
myRequest.Timeout = 10000;�� //������ҳ��Ӧʱ�䳤��
myRequest.AllowAutoRedirect = false;//�Ƿ������Զ��ض���
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
bResult = (myResponse.StatusCode == HttpStatusCode.OK);//������Ӧ��״̬


return bResult;
}
}
}



https://www.cnblogs.com/itjeff/p/5794673.html

http://blog.csdn.net/heyangyi_19940703/article/details/52045348

http://www.cnblogs.com/Leo_wl/category/246422.html

https://developer.github.com/v3/repos/contents/#get-archive-link

http://blog.csdn.net/iastro/article/details/53743691

https://www.cnblogs.com/tdfblog/p/Analysing-C-code-on-GitHub-with-BigQuery.html

https://www.cnblogs.com/liang0722/p/5288186.html

http://www.cnblogs.com/liang0722/p/5288277.html

https://www.zhihu.com/question/28598093?sort=created

https://www.cnblogs.com/yunfeifei/p/4209625.html

https://stackoverflow.com/questions/21625584/download-code-from-github-using-octokit-net
Loading