1

我正在创建 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)
4

0 回答 0