问题描述
我正在尝试使用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.
有趣的是,最可能的选择似乎是因为按照 HttpWebRequest在WP7上中断,但我的AppManifestWM.xaml文件似乎具有以下定义:
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.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上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!