string url = "http://localhost:12083/api/common/GetVerifyCode"; string strType = "application/x-www-form-urlencoded"; string strPar = "userName=18382565651";//拼接参数 HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);//创建请求地址 httpWebRequest.ContentType = strType;//设置http标头 httpWebRequest.Method = "POST";//设置提交方式 httpWebRequest.Timeout = 600000;//设置过期时间 byte[] btBodys = Encoding.UTF8.GetBytes(strPar);//重写字符串为字节码 httpWebRequest.ContentLength = btBodys.Length; httpWebRequest.GetRequestStream().Write(btBodys, 0, btBodys.Length); HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();//接收返回内容 StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream());//读写为流 string responseContent = streamReader.ReadToEnd();//返回的数据 httpWebResponse.Close(); streamReader.Close(); httpWebRequest.Abort(); httpWebResponse.Close();
时间: 2024-10-13 13:15:49