Windows Phone 8 アプリを作成しています。JSON を返す PHP Web サービスを呼び出す必要があります。サービスを呼び出すと、TargetInvocationException
. 詳細とコードを以下に示します。を使用して Windows 8 アプリで同じ Web サービスを呼び出そうとしましたが、HttpClient
正常に動作しています。
private void btnLogin_Click(object sender, RoutedEventArgs e)
{
if (IsValidData())
{
var webClient = new WebClient();
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(new Uri(string.Format(LOGIN_URL, txtUsername.Text, txtPassword.Password)));
}
}
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
var aa = e.Result; //Exception is here
}
An exception of type 'System.Reflection.TargetInvocationException' occurred in System.ni.dll but was not handled in user code
Inner Exception Details:
System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound.
at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClasse.<EndGetResponse>b__d(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass1.<BeginOnUI>b__0(Object sendState)
--- End of inner exception stack trace ---
at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)