using System.Collections; using System.Collections.Generic; using System.IO; using System.Net; using System.Text; using UnityEngine; public class GetQueryPractices : MonoBehaviour { // Start is called before the first frame update void Start() { GetPractices(); } // Update is called once per frame void Update() { } public void GetPractices() { Dictionary formDic = new Dictionary(); formDic.Add("userId", "94"); string result = HttpWebRequestGet("http://124.71.203.22:8080/api/pro/queryPractices", formDic); } /// /// 发送Get请求 /// /// 地址 /// 请求参数定义 /// public static string HttpWebRequestGet(string url, Dictionary dic) { string result = ""; StringBuilder builder = new StringBuilder(); builder.Append(url); if (dic.Count > 0) { builder.Append("?"); int i = 0; foreach (var item in dic) { if (i > 0) builder.Append("&"); builder.AppendFormat("{0}={1}", item.Key, item.Value); i++; } } HttpWebRequest req = (HttpWebRequest)WebRequest.Create(builder.ToString()); //添加参数 HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); Stream stream = resp.GetResponseStream(); try { //获取内容 using (StreamReader reader = new StreamReader(stream)) { result = reader.ReadToEnd(); } } finally { stream.Close(); } Debug.Log("PracticesResult" + result); return result; } }