设置 Uri
Uri urlthree = new Uri("http://cloud.calmcar.com/data/api/vboxpush.action");
设置byte[] 数组
byte[] sssss = System.Text.Encoding.UTF8.GetBytes("fdsafdsafdsa");
另外添加一种byte[]与string 转换(一般电脑程序都是按照byte[]存储字节,例如:{01,02,03,04,262})
string ssssssssss= System.Text.Encoding.UTF8.GetString(sssss);
我们一般常用的的前端 的Ajax 异步请求
后端的请求多用于小程序,可以直接丢服务器上运行,操作简单
虽然后端比前端的请求难一些,不着急
我马上附上后端请求,可以直接copy使用
public static string Http(Uri uri, byte[] data = null) { string rtnVal = ""; int tryTimes = 0; again: tryTimes++; try { HttpWebRequest webRequest = (HttpWebRequest)System.Net.WebRequest.Create(uri); webRequest.Method = "GET"; webRequest.ContentType = "application/x-www-form-urlencoded"; if (data != null) { webRequest.Method = "POST"; webRequest.ContentLength = data.Length; Stream inputStream = webRequest.GetRequestStream(); inputStream.Write(data, 0, data.Length); inputStream.Close(); inputStream.Dispose(); inputStream = null; } HttpWebResponse webResp = (HttpWebResponse)webRequest.GetResponse(); using (Stream receiveStream = webResp.GetResponseStream()) { using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8)) { rtnVal = readStream.ReadToEnd(); } } } catch (Exception) { if (tryTimes < 1) goto again; } return rtnVal; } } }
多组传参
byte[] sssss = System.Text.Encoding.UTF8.GetBytes({\"Action\":\"GetCarMainInfo\",\"CarId\":\"1000707\"});