2011-08-06 35 views
3

我需要從Windows Phone7的應用項目這個API獲取圖像,WP7:無法從URL HTTPGET使用webclient.OpenReadAsync

getvmsimg的img

說明:

API for get variable message sign (VMS) as img 

URL:

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; 
} 

THX,傢伙

+1

您訪問瀏覽器中的第二個url,它會成功嗎? – AnthonyWJones

+0

是的,它顯示img(.png)成功。 – Ratchapol

+0

現在需要挖掘Fiddler工具,檢查瀏覽器在使用該URL時的成功HTTP對話,並將其與Silverlight應用嘗試檢索相同URL的對話進行比較。 – AnthonyWJones

回答

0

你嘗試到整個流(帶緩衝或其他人)寫爲的MemoryStream,然後使用該的MemoryStream而不是直接使用所產生的數據流?