-1
我想從c#
類庫調用json
,下面是我正在使用的代碼。在瀏覽器中訪問json
網址時,我能夠看到相應的數據。但從代碼它是給你沒有權限調用這個URL從C#調用json時的權限被拒絕類
請幫助如何克服這個錯誤。
計劃:
網址:
字符串URL = https://landfill.bugzilla.org/bugzilla-tip/jsonrpc.cgi?method=Product.get & PARAMS = [{」 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;
}
當我改變這讓我越來越喜歡execption – user1899731
現在刪除了發佈數據部分及其正常工作:)非常感謝。 – user1899731
你能告訴我如何在Json中傳遞參數嗎? – user1899731