2013-08-05 150 views
0

我試圖從服務訪問一些數據到我的windows service。 這是一個線程的代碼:Web服務:403禁止的錯誤

HttpWebRequest webrequest = HttpWebRequest.Create(url + "/data.json?auth_token=" + authenticationToken); 
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3; 
System.Net.ServicePointManager.ServerCertificateValidationCallback = 
       ((sender, certificate, chain, sslPolicyErrors) => true); 

webrequest.Method = "GET"; 
webrequest.ContentType = "application/jsonp"; 

HttpWebResponse webresponse = (HttpWebResponse) webrequest.GetResponse(); 
Encoding enc = System.Text.Encoding.GetEncoding("utf-8"); 
StreamReader loResponseStream = new StreamReader(webresponse.GetResponseStream(), enc); 

result = loResponseStream.ReadToEnd(); 

它之前正常工作。但由於幾天,它給錯誤: The remote server returned an error: (403) Forbidden. at System.Net.HttpWebRequest.GetResponse()

編輯:

如果我試圖通過瀏覽器的請求,我得到的反應正常,但不是通過窗口A的服務!

+0

代碼「403 FORBIDDEN」是不言自明的;出於某種原因,它不認爲你被允許這樣做。你對服務器有任何控制權,還是第三方? – anaximander

+0

您的網絡服務是否正在運行?你最近更改了你的Windows密碼,而沒有更新IIS中的pwd詳細信息? –

+0

@anaximander,它是第三方。 – mike44

回答

0

It was working properly before. But since few days, it is giving error

首先檢查:證書是否過期?

+0

當我通過瀏覽器訪問URL時,它正在工作。通過Windows服務呼叫時是否還需要其他因素? – mike44