HttpWebRequest返回“远程服务器返回错误:未找到".在Windows Phone 7上 [英] HttpWebRequest returning "The remote server returned an error: NotFound" on Windows Phone 7

查看:92
本文介绍了HttpWebRequest返回“远程服务器返回错误:未找到".在Windows Phone 7上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Windows Phone 7模拟器针对Huddle API进行身份验证.但是,我没有获得任何成功.我不断收到远程服务器返回错误:NotFound".我什至尝试过简化"我的代码,而只是尝试一个简单的网站,例如. Google,但仍然得到相同的结果.

I am trying to authenticate against the Huddle API using the Windows Phone 7 Emulator. However, I am not getting any success. I keep getting "The remote server returned an error: NotFound". I have even tried "dumbing down" my code and just trying a straight web site, eg. Google but still get the same result.

我有以下代码:

string url = "http://www.google.com"; 

 HttpWebRequest client= WebRequest.CreateHttp(new Uri(url)) as HttpWebRequest;

 client.AllowReadStreamBuffering = true;

 // Call and handle the response.
 client.BeginGetResponse(
  (asResult) =>
  {
   Dispatcher.BeginInvoke(
    () =>
    {
     try
     {
      var response = client.EndGetResponse(asResult);
      System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream());
      string responseString = reader.ReadToEnd();

     }
     catch (WebException failure)
     {
      throw failure;
     }
    });
  },
   null
 );

执行总是在catch部分结束.但是,观看了Fiddler2后,google.com似乎没有任何访问量.因此请求似乎没有被提出.

Execution always ends up in the catch section. However, having watched Fiddler2, there seems not to be any traffic at all to google.com. So the request doesn't seem to be being made.

我在这里看到了类似的问题使用https从XML检索XML WebClient/HttpWebRequest-WP7 ,但是我使用的是标准端口,因此不确定是否相关.我还尝试按照帖子简化代码,但没有成功.

I've seen a similar problem here Retrieve XML from https using WebClient/HttpWebRequest - WP7, but I am using a standard port so not sure this is relevant. I have also tried simplifying the code as per the post, but no success.

有趣的是,最可能的选择似乎是因为按照

Interestingly, the most likely option seems to be because I may not have Network Capabilities defined in my AppManifestWM.xaml file as per HttpWebRequest Breaks On WP7, but my AppManifestWM.xaml file appears to have this defined:

<Deployment xmlns="http://schemas.microsoft.com/windowsphone/2009/deployment" AppPlatformVersion="7.0">
  <App xmlns="" ProductID="{ac5b5d62-573c-4134-b290-0ad4f678ad7f}" Title="xxx.WindowsPhone7.Client" RuntimeType="Silverlight" Version="1.0.0.0" Genre="apps.normal"  Author="xxx.WindowsPhone7.Client author" Description="Sample description" Publisher="xxx.WindowsPhone7.Client publisher">
    <IconPath IsRelative="true" IsResource="false">ApplicationIcon.png</IconPath>
    <Capabilities>
      <Capability Name="ID_CAP_NETWORKING" />
      <Capability Name="ID_CAP_LOCATION" />
      <Capability Name="ID_CAP_SENSORS" />
      <Capability Name="ID_CAP_MICROPHONE" />
      <Capability Name="ID_CAP_MEDIALIB" />
      <Capability Name="ID_CAP_GAMERSERVICES" />
      <Capability Name="ID_CAP_PHONEDIALER" />
      <Capability Name="ID_CAP_PUSH_NOTIFICATION" />
      <Capability Name="ID_CAP_WEBBROWSERCOMPONENT" />
    </Capabilities>
    <Tasks>
      <DefaultTask  Name ="_default" NavigationPage="MainPage.xaml"/>
    </Tasks>
    <Tokens>
      <PrimaryToken TokenID="xxx.WindowsPhone7.ClientToken" TaskName="_default">
        <TemplateType5>
          <BackgroundImageURI IsRelative="true" IsResource="false">Background.png</BackgroundImageURI>
          <Count>0</Count>
          <Title>xxx.WindowsPhone7.Client</Title>
        </TemplateType5>
      </PrimaryToken>
    </Tokens>
  </App>
</Deployment>

所以我很茫然.该请求实际上似乎并未发生,这使我认为某事阻止了该请求.

So I'm at a loss. The request doesn't actually seem to be occurring, leading me to think something is preventing it.

更新:

什么都没有改变,但是以为这个堆栈跟踪可能是错误的:

Nothing changed, but thought this stack trace might heko:

System.Net.WebException未处理 Message =远程服务器返回了一个 错误:未找到.堆栈跟踪: 在System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) 在System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 位于xxx.WindowsPhone7.Client.Views.AddHuddleUserPage.<> c__DisplayClass2.<> c__DisplayClass4.b__1() 在System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi,对象obj,BindingFlags invokeAttr,活页夹活页夹,对象 参数,CultureInfo文化, 布尔值isBinderDefault,程序集 调用者,布尔verifyAccess, StackCrawlMark& stackMark) 在System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj,BindingFlags invokeAttr,活页夹 资料夹,Object []参数, CultureInfo文化,StackCrawlMark& stackMark) 在System.Reflection.MethodBase.Invoke(Object obj,Object []参数) 在System.Delegate.DynamicInvokeOne(Object [] args) 在System.MulticastDelegate.DynamicInvokeImpl(Object [] args) 在System.Delegate.DynamicInvoke(Object [] args) 在System.Windows.Threading.DispatcherOperation.Invoke() 在System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority 优先) 在System.Windows.Threading.Dispatcher.OnInvoke(Object 语境) 在System.Windows.Hosting.CallbackCookie.Invoke(Object [] args) 在System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object [] args) 在System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle,Int32 nParamCount, ScriptParam [] pParams,ScriptParam& pResult)

System.Net.WebException was unhandled Message=The remote server returned an error: NotFound. StackTrace: at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at xxx.WindowsPhone7.Client.Views.AddHuddleUserPage.<>c__DisplayClass2.<>c__DisplayClass4.b__1() at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark) at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at System.Delegate.DynamicInvokeOne(Object[] args) at System.MulticastDelegate.DynamicInvokeImpl(Object[] args) at System.Delegate.DynamicInvoke(Object[] args) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority) at System.Windows.Threading.Dispatcher.OnInvoke(Object context) at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args) at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args) at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)

状态为 System.Net.WebExceptionStatus.UnknownError

感谢您的时间.

推荐答案

好,我已经解决了...但是不知道如何解决.我的机器尚未重新启动,我的代码未更改.唯一可能的解释是我的模拟器确实崩溃了几次.也许在那里.

Ok, I've solved it ... but don't know how. My machine has not been rebooted, my code has not changed. The only possible explanation is my emulator did crash a few times. Maybe something in there.

感谢您的时间,这是我正在使用的代码,它与Huddle API配合使用非常好:

Thanks for your time, this is the code I'm using, which works well with the Huddle API:

                string url = "https://api.huddle.net/v1/xml/workspaces"; ; 

                HttpWebRequest client= WebRequest.CreateHttp(new Uri(url)) as HttpWebRequest;

                client.Credentials = new NetworkCredential(ViewModel.UserAccount.UserName, ViewModel.UserAccount.Password); 
                client.AllowReadStreamBuffering = true;

                // Call and handle the response.
                client.BeginGetResponse(
                    (asResult) =>
                    {
                        Dispatcher.BeginInvoke(
                            () =>
                            {
                                try
                                {
                                    var response = client.EndGetResponse(asResult);
                                    System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream());
                                    string responseString = reader.ReadToEnd();



                                                                        }
                                catch (WebException failure)
                                {
                                    MessageBox.Show(failure.Message, "Cannot authenticate", MessageBoxButton.OK);
#if DEBUG
                                    throw failure;
#endif
                                }
                            });
                    },
                        null
                );

这篇关于HttpWebRequest返回“远程服务器返回错误:未找到".在Windows Phone 7上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆