-1

我正在尝试jsonc#类库中调用,下面是我正在使用的代码。在浏览器中访问jsonurl 时,我可以看到相应的数据。但是从代码中它给了你没有权限调用这个 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;
}
4

1 回答 1

0

你在做一个“GET”而不是一个 POST 对吗?

改变这个:

webRequest.Method = "POST";

webRequest.Method = "GET";
于 2012-12-13T03:51:05.813 回答