嘗試了一天,嘗試了各種方法,一下方法最直接方便. ...
嘗試了一天,嘗試了各種方法,一下方法最直接方便.
//地址 string _url = "https://www.dXXXayup.ink/api/User/Login"; //json參數 string jsonParam = "{ phonenumber:\"18665885202\",pwd:\"tsp\"}"; var request = (HttpWebRequest)WebRequest.Create(_url); request.Method = "POST"; request.ContentType = "application/json;charset=UTF-8"; byte[] byteData = Encoding.UTF8.GetBytes(jsonParam); int length = byteData.Length; request.ContentLength = length; Stream writer = request.GetRequestStream(); writer.Write(byteData, 0, length); writer.Close(); var response = (HttpWebResponse)request.GetResponse(); var responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd(); MessageBox.Show(responseString.ToString());