I am trying to call json from c# class library and below is the code I am using. While accessing the json url in browser, I am able to see the respective data. But from code it is giving You dont have permission to call this URL
Please help how to overcome this error.
Program:
URL:
string url= https://landfill.bugzilla.org/bugzilla-tip/jsonrpc.cgi?method=Product.get¶ms=%5B{“ids”:”4″}]
try
{
string ret = string.Empty;
StreamWriter requestWriter;
var webRequest = System.Net.WebRequest.Create(url) as HttpWebRequest;
if (webRequest != null)
{
webRequest.Method = "POST";
webRequest.ServicePoint.Expect100Continue = false;
webRequest.Timeout = 20000;
webRequest.ContentType = "application/json";
//POST the data.
using (requestWriter = new StreamWriter(webRequest.GetRequestStream()))
{
requestWriter.Write(postData);
}
}
HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse();
Stream resStream = resp.GetResponseStream();
StreamReader reader = new StreamReader(resStream);
ret = reader.ReadToEnd();
return ret;
}
catch (WebException exception)
{
string responseText;
using (var reader = new StreamReader(exception.Response.GetResponseStream()))
{
responseText = reader.ReadToEnd();
}
return responseText;
}
You’re doing a “GET” not a POST right?
Change this:
to