GET
PUT
req.Method = "PUT";
using System; using System.Text; using System.Net; using System.IO; // =========================================== try { string WebServiceURL = tbWebServiceURL.Text; // store Url Of service in string // Convert our JSON in into bytes using ascii encoding ASCIIEncoding encoding = new ASCIIEncoding(); byte[] data = encoding.GetBytes(tbJSONdata.Text); // HttpWebRequest HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(WebServiceURL); webrequest.Method = "POST"; webrequest.ContentType = "application/x-www-form-urlencoded"; webrequest.ContentLength = data.Length; // Get stream data out of webrequest object Stream newStream = webrequest.GetRequestStream(); newStream.Write(data, 0, data.Length); newStream.Close(); // Declare & read the response from service HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse(); // Fetch the response from the POST web service Encoding enc = System.Text.Encoding.GetEncoding("utf-8"); StreamReader loResponseStream = new StreamReader(webresponse.GetResponseStream(), enc); string result = loResponseStream.ReadToEnd(); loResponseStream.Close(); webresponse.Close(); txtResult.Text = result; } catch (Exception ex) { txtResult.Text = "An exception was thrown: " + ex.Message; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)