Zuletzt bearbeitet vor 12 Jahren
von Supervisor

C

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace Bfx.PostAXML.Sample
{
   class PostAXML
   {
       Uri myUri;
       String myAXML;
       public PostAXML(String host, int port, String url, String axml)
       {
           myUri = new Uri("http://" + host + ":" + port + "/" + url);
           myAXML = axml;
       }
       public HttpWebRequest GetRequest()
       {
           HttpWebRequest request = (HttpWebRequest)WebRequest.Create(myUri);
           request.Credentials = CredentialCache.DefaultCredentials;
           request.UserAgent = "PostAXML";
           request.KeepAlive = true;
           request.Method = "POST";
           byte[] data = System.Text.Encoding.ASCII.GetBytes(myAXML);
           request.ContentLength = data.Length;
           Stream tempStream = request.GetRequestStream();
           tempStream.Write(data, 0, data.Length);
           tempStream.Close();
           return request;
       }
       public HttpWebResponse GetResponse(HttpWebRequest request)
       {
           HttpWebResponse response = (HttpWebResponse)request.GetResponse();
           return response;
       }
       static void Main(string[] args)
       {
           String axml = "<root><Department id=\"#100\" label=\"TEST\" ></Department></root>";
           PostAXML postAXML = new PostAXML("127.0.0.1", 4480, "AXML", axml);

           try
           {
               HttpWebResponse response = postAXML.GetResponse(postAXML.GetRequest());
               StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.ASCII);
               Console.WriteLine(sr.ReadToEnd());
               sr.Close();
           }
           catch (WebException WebExcp)
           {
               Console.WriteLine(WebExcp.Message.ToString());
           }
           catch (Exception e)
           {
               Console.WriteLine(e.Message.ToString());
           }
       }
   }
}