call HttpHandler

  • Post author:
  • Post category:其他


private void Send() { WebResponse response; StreamReader reader; //要传递的XML字串 string msg = txtStr.Text; byte[] sourceByte = Encoding.UTF8.GetBytes(msg); string bs64Str = Convert.ToBase64String(sourceByte); //将要传递的XML字串转换为Base64字串 byte[] byteArray = Encoding.UTF8.GetBytes(bs64Str); string uri = “http://ctwebtest/TmsListener/TMS.ashx”; WebRequest request = WebRequest.Create(uri); request.Method = “POST”; request.ContentType = “application/x-www-form-urlencoded”; request.ContentLength = byteArray.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); try { response = request.GetResponse(); dataStream = response.GetResponseStream(); reader = new StreamReader(dataStream); //获得返回的StatusCode txtCode.Text = ((Int32)(((HttpWebResponse)response).StatusCode)).ToString(); } catch (WebException ex) { txtCode.Text = ex.Message; } finally { dataStream.Close(); if (reader != null) reader.Close(); if (response != null) response.Close(); } }



版权声明:本文为sophiazhou原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。