call HttpHandler

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(); } }

你可能感兴趣的:(xml)