2011-05-18 99 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

相关问题