我正在尝试json
从c#
类库中调用,下面是我正在使用的代码。在浏览器中访问json
url 时,我可以看到相应的数据。但是从代码中它给了你没有权限调用这个 URL
请帮助如何克服这个错误。
程序:
网址:
字符串 url= https://landfill.bugzilla.org/bugzilla-tip/jsonrpc.cgi?method=Product.get¶ms=[{"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;
}