0
我有下面的響應代碼。我得到的錯誤就像在System.Windows.ni.dll中發生類型'System.UnauthorizedAccessException'的異常,但是在調用Messagebox時沒有在用戶代碼錯誤中處理。 SOHW()方法來顯示的代碼:200 我的JSON是例如{「元」:{「代碼」:200}}htttwebresponse方法中的Messagebox.show錯誤
private void ReadWebRequestCallback(IAsyncResult ar)
{
HttpWebRequest myReq = (HttpWebRequest)ar.AsyncState;
HttpWebResponse myResponse = (HttpWebResponse)myReq.EndGetResponse(ar);
uritext.Text = myResponse.ResponseUri.ToString();
using (StreamReader httpwebStreamReader = new StreamReader(myResponse.GetResponseStream()))
{
string results = httpwebStreamReader.ReadToEnd();
}
myResponse.Close();
var root = JsonConvert.DeserializeObject<RootObject>(jsondata);
String codenum = root.meta.code.ToString();
Messagebox.sohw(codenum);
}
public class Meta
{
public int code { get; set; }
}
public class RootObject
{
public Meta meta { get; set; }
}
我怎麼可以使用HttpWebRequest的避免這個問題? protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { String accesstoken = NavigationContext.QueryString [「access_token」]; HttpWebRequest myReq =(HttpWebRequest)WebRequest.Create(access_uri + accesstoken); myReq.BeginGetResponse(new AsyncCallback(ReadWebRequestCallback),myReq); } –
只需將ReadWebRequestCallback方法中調用MessageBox.Show的行替換爲寫在我的答案中的代碼即可。 –
如何在Dispatcher.BeginInvoke()中傳遞類似test()的方法; –