2011-05-24 65 views
1

我想在Job或Winforms應用程序中生成QR碼。從C#應用程序調用Google Chart API的問題

我的API調用非常簡單:

http://chart.apis.google.com/chart?cht=qr&chld=L|0&chs=80x80&chl=http%3a%2f%2futip.it.%2ft%2f1833 

當我把它從瀏覽器的罰款。

當我把它用下面的代碼,我得到一個超時錯誤:

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); 
request.Timeout = 5000; 
request.ReadWriteTimeout = 5000; 
request.ContentType = "image/png"; 
HttpWebResponse imgresponse = (HttpWebResponse)request.GetResponse(); 
System.Drawing.Image img = System.Drawing.Image.FromStream(imgresponse.GetResponseStream()); 

當我打開提琴手調試的要求,它的工作原理。我假設我需要在請求上設置一些標題。我已經嘗試了一些,但沒有成功..

回答

0

真的不明白爲什麼,但使用此代碼的工作:

byte[] fileBytes = null; 

    WebClient client = new WebClient(); 
    fileBytes = client.DownloadData(url); 
    MemoryStream theMemStream = new MemoryStream(); 

    theMemStream.Write(fileBytes, 0, fileBytes.Length); 
    System.Drawing.Image img2 = System.Drawing.Image.FromStream(theMemStream); 
相關問題