方便快捷,记录一下!
void Start() {
HttpRequest("我在请求内容","http://localhost:8000//demo//abc");
}
public void HttpRequest(string postData,string url) {
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(postData);
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url));
webRequest.Method = "POST";
webRequest.ContentType = "text/plain";
webRequest.ContentLength = byteArray.Length;
Stream newStream = webRequest.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);
newStream.Close();
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
Debug.Log("响应我的消息:"+sr.ReadToEnd());
}