Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How to put and post request using HttpWebRequest

$
0
0

Hi,

I got error The remote server returned an error: (400) Bad Request. when execute this line HttpWebResponse response = (HttpWebResponse)request.GetResponse();

my code is:

    try
         {
             string _url = "http://mydomain/Api/Log/"; 

             string str = id.ToString();
             System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
             byte[] arr = encoding.GetBytes(str);
             HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(_url);
             request.AllowWriteStreamBuffering = false;
             request.Method = "POST";

             request.ContentType = "application/json";
             request.ContentLength = arr.Length;

             Stream dataStream = request.GetRequestStream();
             dataStream.Write(arr, 0, arr.Length);
             dataStream.Close();
             HttpWebResponse response = (HttpWebResponse)request.GetResponse();
             string returnString = response.StatusCode.ToString();
         }
         catch(WebException ex) {
             Android.Util.Log.Error("http errror", ex.Message );
         }

i want to know how it works for post and put json request AND please GUIDE for writing "url" of web request for Post and put.

please help to solve this.

Thanks


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>