开发者

My post request to https://qrng.physik.hu-berlin.de/ failed, why?

the开发者_高级运维 page at https://qrng.physik.hu-berlin.de/ provides a high bit rate quantum number generator web service and I'm trying to access that service.

However I could not manage to do so. This is my current code:

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

        }
    }

}

I'm having 403 forbidden error when I try to do a get request on http://qrng.physik.hu-berlin.de/download/sampledata-1MB.bin.

After debugging abit, I've realised that even though I've supplied a valid username and password, the response html that was sent after my POST request indicate that I was actually not logon to the system after my POST request.

Does anyone know why is this the case, and how may I work around it to call the service?

Bump. can anyone get this to work or is the site just a scam?


The site is surely not a scam. I developed the generator and I put my scientific reputation in it. The problem is that you are trying to use the service in a way that was not intended. The sample files were really only meant to be downloaded manually for basic test purposes. Automated access to fetch data into an application was meant to be implemented through the DLLs we provide. On the other hand, I do not know of any explicit intent to prevent your implementation to work. I suppose if a web browser can log in and fetch data, some program should be able to do the same. Maybe only the login request is just a little more complicated. No idea. The server software was developed by someone else and I cannot bother him with this right now.

Mick


Actually, the generator can now also be purchased. See here: http://www.picoquant.com/products/pqrng150/pqrng150.htm


Have you tried to change this

my_request.Credentials = System.Net.CredentialCache.DefaultCredentials

to

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

as described on MSDN page?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜