【问题标题】:WP7: can't get img from httpget url using webclient.OpenReadAsyncWP7:无法使用 webclient.OpenReadAsync 从 httpget url 获取 img
【发布时间】: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


【解决方案1】:

您是否尝试将整个流(使用缓冲区或其他)写入 MemoryStream,然后使用该 MemoryStream 而不是直接使用生成的流? p>

【讨论】:

    猜你喜欢
    • 2019-02-01
    • 2014-11-29
    • 2012-05-07
    • 1970-01-01
    • 2015-03-13
    • 1970-01-01
    • 2021-03-28
    • 2015-12-17
    • 2020-09-02
    相关资源
    最近更新 更多