Как разместить данные с помощью httpwebrequest в c#.net
try { string url = "http://xyz.co.in:8080/register"; string postdata = "uid" + uid + "userid" + userid + "password" + password + "emailid" + emailid + "isotemplate"+ isotemplate + "mobileno" + mobileno + "deviceserialid" + deviceserialid + "compmacaddress" + compmacaddress + "kioskid" + kioskid + "kioskhandler" + kioskhandler + "devicename" + devicename + "devicemodel" + devicemodel; byte[] data = Encoding.UTF8.GetBytes(postdata); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.KeepAlive = false; request.ProtocolVersion = HttpVersion.Version10; request.Method = "POST"; // turn our request string into a byte stream byte[] postBytes = Encoding.UTF8.GetBytes(postdata); // this is important - make sure you specify type this way request.ContentType = "application/json; charset=UTF-8"; request.Accept = "application/json"; request.ContentLength = postBytes.Length; //request.CookieContainer = Cookies; //request.UserAgent = currentUserAgent; Stream requestStream = request.GetRequestStream(); // now send it requestStream.Write(postBytes, 0, postBytes.Length); requestStream.Close(); // grab te response and print it out to the console along with the status code HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string result; using (StreamReader rdr = new StreamReader(response.GetResponseStream())) { result = rdr.ReadToEnd(); }
Что я уже пробовал:
сообщение об ошибке удаленного сервера bad 400
Graeme_Grant
Вы захватываете WebException, а не только класс исключений по умолчанию? Что говорит InnerException?