Пример #1
0
        public void SaveDriver(Driver d)
        {
            // Create a request using a URL that can receive a post.
            WebRequest request = WebRequest.Create(serverURL + "/Api/Driver");

            // Set the Method property of the request to POST.
            request.Method = "POST";
            string postData = JsonConvert.SerializeObject(d);

            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            // Set the ContentType property of the WebRequest.
            request.ContentType = "application/json";
            // Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length;
            // Get the request stream.
            Stream dataStream = request.GetRequestStream();

            // Write the data to the request stream.
            dataStream.Write(byteArray, 0, byteArray.Length);
            // Close the Stream object.
            dataStream.Close();
            try
            {
                WebResponse response = request.GetResponse();
            }
            catch (WebException e)
            {
                DisplayHandler.printError(e);
            }
        }
Пример #2
0
        public void UpdatePackage(int id, Package p)
        {
            WebRequest request = WebRequest.Create(serverURL + "/Api/Package/" + id);

            request.Method = "PUT";
            string postData = JsonConvert.SerializeObject(p);

            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            // Set the ContentType property of the WebRequest.
            request.ContentType = "application/json";
            // Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length;
            // Get the request stream.
            Stream dataStream = request.GetRequestStream();

            // Write the data to the request stream.
            dataStream.Write(byteArray, 0, byteArray.Length);
            // Close the Stream object.
            dataStream.Close();
            try
            {
                WebResponse response = request.GetResponse();
            }
            catch (WebException e)
            {
                DisplayHandler.printError(e);
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            //WebRequest request = WebRequest.Create("http://localhost:52497/Api/Driver/");
            //WebResponse response = request.GetResponse();
            //Console.WriteLine(((HttpWebResponse)response).StatusDescription);
            //// Get the stream containing content returned by the server.
            //Stream dataStream = response.GetResponseStream();
            //// Open the stream using a StreamReader for easy access.
            //StreamReader reader = new StreamReader(dataStream);
            //// Read the content.
            //string responseFromServer = reader.ReadToEnd();

            //var list = JsonConvert.DeserializeObject<List<Driver>>(responseFromServer);
            //Console.ReadLine();
            DisplayHandler d = new DisplayHandler();

            d.DisplayStart();
        }