Original:
http://www.imooc.com/article/8913
Own examples:
web.config
<appSettings>
<add key="GmailUrl" value="https://aaa/bbb/ccc/"/>
</appSettings>
private string GetUserAddress(string id)
{
try
{
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
string url = ConfigurationManager.AppSettings["GmailUrl"] + id;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.ContentType = "text/html;charset=UTF-8";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader streamReader = new StreamReader(stream, Encoding.GetEncoding("utf-8"));
string retString = streamReader.ReadToEnd();
streamReader.Close();
stream.Close();
response.Close();
JArray value = (JArray)JsonConvert.DeserializeObject (retString);
return value[0]["Address"].ToString();
}
catch (Exception)
{
return "";
}
}
Of course, also need Newtonsoft.Json.dll
Further, if it is a beginning with https, also you need to add ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; to establish a secure connection.
Reproduced in: https: //www.cnblogs.com/mabelhua/p/6708048.html