登錄時,密碼+CKEY密碼驗證
讀GCM配置,判定賬號是否需要驗證;需要驗證,就拆分字符串,后六位+剩余部分;post請求去驗證
1.AESUtil對稱加密
2.HttpWebRequest、HttpWebResponse、StreamReader
- 創(chuàng)建請求,獲取響應(yīng)流;
- 請求分get、post兩種方式;(*)
- 讀取響應(yīng)流信息,用到StreamReader ,string類型的(符合JSON格式的)
- JSON格式、實體類(實體列表)之間的轉(zhuǎn)化
public static string HttpPost(string url, string jsonStr)
{
HttpWebRequest request = null;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3
| (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback((sender, certificate, chain, errors) => true);//驗證服務(wù)器證書回調(diào)自動驗證
try
{
request = (HttpWebRequest)WebRequest.Create(url);//創(chuàng)建一個HTTP請求
}
catch (Exception ex)
{
Console.WriteLine("Http Post請求 創(chuàng)建失敗!" + ex.Message);
//throw new Exception("Http請求創(chuàng)建失敗", ex);
return null;
}
request.Method = "POST";//Post請求方式
request.ContentType = "application/json";//內(nèi)容類型
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36";
byte[] byteArray;//設(shè)置參數(shù),并進行URL編碼
if (jsonStr == null)
{
jsonStr = "";
}
byteArray = System.Text.Encoding.UTF8.GetBytes(jsonStr);//將Json字符串轉(zhuǎn)化為字節(jié)byte數(shù)組
request.ContentLength = byteArray.Length;//設(shè)置請求的ContentLength
Stream writer;
try
{
writer = request.GetRequestStream();//獲取用于寫入請求數(shù)據(jù)的Stream對象
}
catch (Exception ex)
{
Console.WriteLine("獲取Http請求寫入流失敗!" + ex.Message);
return null;
}
writer.Write(byteArray, 0, byteArray.Length);//將請求參數(shù)寫入流
writer.Close();//關(guān)閉請求流
HttpWebResponse response;
try
{
response = (HttpWebResponse)request.GetResponse();//獲得響應(yīng)流
}
catch (WebException ex)
{
Console.WriteLine("獲取Http響應(yīng)流失敗!" + ex.Message);
return null;
}
Stream responseStream = response.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding("UTF-8"));
string postContent = streamReader.ReadToEnd();
streamReader.Close();
return postContent;//Post請求后服務(wù)器返回的數(shù)據(jù)
}
}
3.C#使用JavaScriptSerializer類實現(xiàn)序列化與反序列化
System.Web.Script.Serialization 命名空間

列表→JSON,序列化;JSON→列表,反序列化
C#使用JavaScriptSerializer類實現(xiàn)序列化與反序列化得到JSON_c# javascriptserializer-CSDN博客

浙公網(wǎng)安備 33010602011771號