curl Request with ASP.NET curl Request with ASP.NET curl curl

curl Request with ASP.NET


The default HTTP method for WebRequest is GET. Try setting it to POST, as that's what the API is expecting

myReq.Method = "POST";

I assume you are posting something. As a test, I'm going to post the same data from their curl example.

string url = "https://YOUR_COMPANY_HERE.beebole-apps.com/api";string data = "{\"service\":\"absence.list\", \"company_id\":3}";WebRequest myReq = WebRequest.Create(url);myReq.Method = "POST";myReq.ContentLength = data.Length;myReq.ContentType = "application/json; charset=UTF-8";string usernamePassword = "YOUR API TOKEN HERE" + ":" + "x";UTF8Encoding enc = new UTF8Encoding();myReq.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(enc.GetBytes(usernamePassword)));using (Stream ds = myReq.GetRequestStream()){ds.Write(enc.GetBytes(data), 0, data.Length); }WebResponse wr = myReq.GetResponse();Stream receiveStream = wr.GetResponseStream();StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);string content = reader.ReadToEnd();Response.Write(content);