zoukankan      html  css  js  c++  java
  • 后端服务器请求

    设置 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[]存储字节)

    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"});
  • 相关阅读:
    GCD 并行子线程
    iOS开发>学无止境
    iOS开发>学无止境
    iOS开发>学无止境
    FMDB使用
    递归
    局部变量与全局变量
    函数式编程与参数
    文件的操作
    集合的操作
  • 原文地址:https://www.cnblogs.com/wuhuiting-0617/p/9779023.html
Copyright © 2011-2022 走看看