【发布时间】:2011-10-21 10:16:00
【问题描述】:
我需要在 Windows phone7 应用程序上从此 API 获取图像,
getvmsimg
说明:
API for get variable message sign (VMS) as img
网址:
http://athena.traffy.in.th/apis/apitraffy.php?api=…&id=…[w=...]&[h=...]
格式:
Image: PNG
HTTP 方法:
GET
需要身份验证:
true
API 速率限制:
unlimited
这是我的代码 我必须首先通过另一个 API 获取会话密钥(完全,没问题),然后我必须使用会话密钥作为 httpget url 中的参数。 我的钥匙是正确的 100%,我已经检查过了。 但它在 "image.SetSource(e.Result);" 处出错行(未指定的错误)。
public intsign()
{
InitializeComponent();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
client.DownloadStringAsync(new Uri("http://api.traffy.in.th/apis/getKey.php?appid="+appid));
}
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
rd = e.Result;
sessionkey = MD5Core.GetHashString(appid + rd) + MD5Core.GetHashString(hiddenkey + rd);
//MessageBox.Show(sessionkey);
client2.OpenReadCompleted += new OpenReadCompletedEventHandler(client2_OpenReadCompleted);
client2.OpenReadAsync(new Uri("http://athena.traffy.in.th/apis/apitraffy.php?api=getvmsimg&key=" + sessionkey + "&appid=" + appid + "&id=1&h=480&w=480"),client2);
}
void client2_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
BitmapImage image = new BitmapImage();
image.SetSource(e.Result);
intsignimg.Source = image;
}
谢谢,伙计
【问题讨论】:
-
你在浏览器中访问第二个url成功了吗?
-
是的,成功显示img(.png)。
-
是时候挖掘 Fiddler 工具了,检查您的浏览器在使用该 URL 时成功进行的 HTTP 会话,并将其与您的 Silverlight 应用程序尝试检索相同 URL 的会话进行比较。
标签: silverlight windows-phone-7 webclient http-get