我正在使用来自 Windows Azure Marketplace 的 Bing Translator API 和访问令牌,并且我得到了应用程序中定义的语言代码
它有时有效,有时无效,并且会引发如下错误:
System.Windows.ni.dll 中出现“System.UnauthorizedAccessException”类型的异常,但未在用户代码中处理
我两次更改了访问令牌(clientId,clientSecret),它首先工作,然后再次开始显示此异常,我到处搜索,但找不到解决方案,这是使用的代码:
private void TranslationReady(IAsyncResult ar)
{
try
{
HttpWebRequest request = (HttpWebRequest)ar.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(ar);
System.IO.Stream streamResponse = response.GetResponseStream();
System.IO.StreamReader streamRead = new System.IO.StreamReader(streamResponse);
string responseString = streamRead.ReadToEnd();
System.Xml.Linq.XDocument xTranslation =
System.Xml.Linq.XDocument.Parse(responseString);
string strTest = xTranslation.Root.FirstNode.ToString();
Deployment.Current.Dispatcher.BeginInvoke(() => TextBlock2.Text = strTest);
}
catch (WebException e)
{
var status = e.Status;
var response = e.Response;
var msg = e.Message;
MessageBox.Show(status.ToString() + response.ToString() + msg.ToString());
}
}