我总是得到远程服务器返回:执行httpwebrequest时找不到

时间:2014-08-12 11:11:45

标签: c# windows-phone-8

我正在开发windows phone 8应用程序,当我尝试执行httpwebrequest时,我总是得到远程服务器返回错误:找不到但是当我在fiddler 2中调试URI时,我得到了正确的结果。

El código de usuario no controló System.Net.WebException
HResult=-2146233079
Message=The remote server returned an error: NotFound.
Source=System.Windows
StackTrace:
   at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
   at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at AplicacionMusical.BiographyPage.ReadWebRequestCallback(IAsyncResult callBackResult)
   at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClass1d.<InvokeGetResponseCallback>b__1b(Object state2)
   InnerException: System.Net.WebException
   HResult=-2146233079
   Message=The remote server returned an error: NotFound.
   Source=System.Windows
   StackTrace:
        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)
   InnerException: 

这是导致此错误的源代码:

Uri targetUri = new Uri("http://192.168.x.x/apptfg/get_group_biography.php?nombre_grupo=" + groupname);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(targetUri);
request.BeginGetResponse(new AsyncCallback(ReadWebRequestCallback), request);

,ReadWebRequestCallback的代码是:

        private void ReadWebRequestCallback(IAsyncResult callBackResult)
    {
        HttpWebRequest myRequest = (HttpWebRequest)callBackResult.AsyncState;
        HttpWebResponse myResponse = (HttpWebResponse)myRequest.EndGetResponse(callBackResult);
            using (StreamReader httpwebStreamReader = new StreamReader(myResponse.GetResponseStream()))
            {
                string results = httpwebStreamReader.ReadToEnd();

                Dispatcher.BeginInvoke(() => DescriptionBox.Text = results);
            }

    }

我想尽快给你一些帮助。

0 个答案:

没有答案