2011-05-18 117 views
0

https://qrng.physik.hu-berlin.de/的頁面提供了一個高比特率的量子數生成器Web服務,我試圖訪問該服務。我的帖子請求https://qrng.physik.hu-berlin.de/失敗了,爲什麼?

但是我無法做到這一點。這是我當前的代碼:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using S=System.Text; 
using System.Security.Cryptography; 
using System.IO; 
namespace CS_Console_App 
{ 
    class Program 
    { 
     static void Main() 
     { 
      System.Net.ServicePointManager.Expect100Continue = false; 
      var username = "testuser"; 
      var password = "testpass"; 
      System.Diagnostics.Debug.WriteLine(Post("https://qrng.physik.hu-berlin.de/", "username="+username+"&password="+password)); 
      Get("http://qrng.physik.hu-berlin.de/download/sampledata-1MB.bin"); 
     } 
     public static void Get(string url) 
     { 
      var my_request = System.Net.WebRequest.Create(url); 
      my_request.Credentials = System.Net.CredentialCache.DefaultCredentials; 
      var my_response = my_request.GetResponse(); 
      var my_response_stream = my_response.GetResponseStream(); 
      var stream_reader = new System.IO.StreamReader(my_response_stream); 
      var content = stream_reader.ReadToEnd(); 
      System.Diagnostics.Debug.WriteLine(content); 
      stream_reader.Close(); 
      my_response_stream.Close(); 
     } 
     public static string Post(string url, string data) 
     { 


      string vystup = null; 
      try 
      { 
       //Our postvars 
       byte[] buffer = System.Text.Encoding.ASCII.GetBytes(data); 
       //Initialisation, we use localhost, change if appliable 
       System.Net.HttpWebRequest WebReq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); 
       //Our method is post, otherwise the buffer (postvars) would be useless 
       WebReq.Method = "POST"; 
       //We use form contentType, for the postvars. 
       WebReq.ContentType = "application/x-www-form-urlencoded"; 
       //The length of the buffer (postvars) is used as contentlength. 
       WebReq.ContentLength = buffer.Length; 
       //We open a stream for writing the postvars 
       Stream PostData = WebReq.GetRequestStream(); 
       //Now we write, and afterwards, we close. Closing is always important! 
       PostData.Write(buffer, 0, buffer.Length); 
       PostData.Close(); 
       //Get the response handle, we have no true response yet! 
       System.Net.HttpWebResponse WebResp = (System.Net.HttpWebResponse)WebReq.GetResponse(); 
       //Let's show some information about the response 
       Console.WriteLine(WebResp.StatusCode); 
       Console.WriteLine(WebResp.Server); 

       //Now, we read the response (the string), and output it. 
       Stream Answer = WebResp.GetResponseStream(); 
       StreamReader _Answer = new StreamReader(Answer); 
       vystup = _Answer.ReadToEnd(); 

       //Congratulations, you just requested your first POST page, you 
       //can now start logging into most login forms, with your application 
       //Or other examples. 
      } 
      catch (Exception ex) 
      { 
       throw ex; 
      } 
      return vystup.Trim() + "\n"; 

     } 
    } 

} 
我有403禁止錯誤,當我嘗試做 http://qrng.physik.hu-berlin.de/download/sampledata-1MB.bin GET請求

調試升技後,我意識到,即使我提供了有效的用戶名和密碼,在POST請求後發送的響應html表明我實際上沒有在POST請求後登錄系統。

有誰知道爲什麼會出現這種情況,我該如何解決它以致電該服務?

凹凸。任何人都可以得到這個工作或是網站只是一個騙局?

+0

你確定你的網址與用戶名和密碼實際上是一種有效的方式登錄到該網站? – 2011-05-18 08:10:59

+0

你似乎沒有使用用戶名和密碼的定義變量? – Michel 2011-05-18 08:36:33

+0

@Daniel Hilgarth是它的有效。您可以嘗試創建一個帳戶並自己分配值。 – Pacerier 2011-05-18 08:45:14

回答

4

該網站肯定不是一個騙局。我開發了發生器,並將其科學信譽放在其中。問題在於你試圖以一種無意的方式使用該服務。示例文件實際上只是爲了基本的測試目的而手動下載。將數據提取到應用程序中的自動訪問意味着通過我們提供的DLL來實現。另一方面,我不知道有任何明確的意圖阻止您的實施工作。我想如果一個Web瀏覽器可以登錄和獲取數據,一些程序應該能夠做到這一點。也許只有登錄請求稍微複雜一點。不知道。服務器軟件是由其他人開發的,現在我無法用它來打擾他。

米克

+0

heys thx的答覆。只有一個問題:樣本數據是「舊樣本」還是「熱生成」隨機數(現在仍在使用?) – Pacerier 2011-05-27 10:51:04

+0

@Prier這些文件總是剛剛生成並且現在仍在運行。磁盤緩存可能會產生唯一的「故障」,但不會有多次緩存數據被傳送。 – Mick 2011-05-27 12:46:33

0

你試過描述on MSDN page改變這種

my_request.Credentials = System.Net.CredentialCache.DefaultCredentials 

my_request.Credentials = new NetworkCredential(UserName,Password); 

+0

中工作。我已經嘗試過,但仍然禁止302。 – Pacerier 2011-05-18 08:58:02

+0

我創建了一個測試用戶。用戶名是testuser,密碼是testpass。 (如果你需要該帳戶來測試)看到我編輯的問題 – Pacerier 2011-05-18 08:59:03

相關問題