rejetto forum

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - DMP9_MC

Pages: 1
1
Programmers corner / Re: Upload programatically on HFS? (C#)
« on: April 18, 2015, 09:22:11 AM »
^ Thats my original code

2
Programmers corner / Re: Upload programatically on HFS? (C#)
« on: April 18, 2015, 09:20:44 AM »
    public void PostMultipleFiles(string url, string[] files)
{
    string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x");
    HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
    httpWebRequest.ContentType = "multipart/form-data; boundary=" + boundary;
    httpWebRequest.Method = "POST";
    httpWebRequest.KeepAlive = true;
    httpWebRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
    Stream memStream = new System.IO.MemoryStream();
    byte[] boundarybytes =System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary     +"\r\n");
    string formdataTemplate = "\r\n--" + boundary + "\r\nContent-Disposition:  form-data; name=\"{0}\";\r\n\r\n{1}";
    string headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n Content-Type: application/octet-stream\r\n\r\n";
    memStream.Write(boundarybytes, 0, boundarybytes.Length);
    for (int i = 0; i < files.Length; i++)
    {
        string header = string.Format(headerTemplate, "file" + i, files);
        //string header = string.Format(headerTemplate, "uplTheFile", files);
        byte[] headerbytes = System.Text.Encoding.UTF8.GetBytes(header);
        memStream.Write(headerbytes, 0, headerbytes.Length);
        FileStream fileStream = new FileStream(files, FileMode.Open,
        FileAccess.Read);
        byte[] buffer = new byte[1024];
        int bytesRead = 0;
        while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
        {
            memStream.Write(buffer, 0, bytesRead);
        }
        memStream.Write(boundarybytes, 0, boundarybytes.Length);
        fileStream.Close();
    }
    httpWebRequest.ContentLength = memStream.Length;
    Stream requestStream = httpWebRequest.GetRequestStream();
    memStream.Position = 0;
    byte[] tempBuffer = new byte[memStream.Length];
    memStream.Read(tempBuffer, 0, tempBuffer.Length);
    memStream.Close();
    requestStream.Write(tempBuffer, 0, tempBuffer.Length);
    requestStream.Close();
    try
    {
        WebResponse webResponse = httpWebRequest.GetResponse();
        Stream stream = webResponse.GetResponseStream();
        StreamReader reader = new StreamReader(stream);
        string var = reader.ReadToEnd();

    }
    catch (Exception ex)
    {
        response.InnerHtml = ex.Message;
    }
    httpWebRequest = null;
}

3
HFS ~ HTTP File Server / Re: usability: index.html by default ?
« on: April 18, 2015, 09:19:05 AM »
Sorry to bring up an inactive post, but is it possible to make it so on the index.html you could press a "Files" button to reload the page, bypassing the index.html?

4
Programmers corner / Re: Upload programatically on HFS? (C#)
« on: March 01, 2015, 04:37:32 PM »
After doing the code below, it didn't register as an upload. Instead it registered as a GET, not POST.


            try
            {
                var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://PlusAPI:dmp9hosting_@dmp9software.ngrok.com/DMP9%20Hosting%20builds");
                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method = "POST";

                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = "{\"agent\":{\"name\":\"Minecraft\",\"version\":1},\"username\":\"" + username + "\",\"password\":\"" + password + "\",\"clientToken\":\"6c9d237d-8fbf-44ef-b46b-0b8a854bf391\"}";

                    streamWriter.Write(json);
                    streamWriter.Flush();
                    streamWriter.Close();

                    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                    {
                        var result = streamReader.ReadToEnd();
                        Console.WriteLine(result);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            Console.Read();

5
Programmers corner / Re: Upload programatically on HFS? (C#)
« on: March 01, 2015, 04:19:18 PM »
Ok. I'm no longer using the UploadFile method. I'm using the same method i used to make a JSON POST request, but customizing it

6
Programmers corner / Upload programatically on HFS? (C#)
« on: February 15, 2015, 06:08:36 PM »
Hi...

I dont know if anyone here is a programmer, and more specifically C#, but im trying to upload a file to HFS using C# WebClient. Heres my code:

            Console.Write("\nPlease enter the URI to post data to : ");
            String uriString = Console.ReadLine();

            // Create a new WebClient instance.
            WebClient myWebClient = new WebClient();

            Console.WriteLine("\nPlease enter the fully qualified path of the file to be uploaded to the URI");
            string fileName = Console.ReadLine();
            Console.WriteLine("Uploading {0} to {1} ...", fileName, uriString);

            // Upload the file to the URI.
            // The 'UploadFile(uriString,fileName)' method implicitly uses HTTP POST method.
            byte[] responseArray = myWebClient.UploadFile(uriString, "POST", fileName);

            // Decode and display the response.
            Console.WriteLine("\nResponse Received.The contents of the file uploaded are:\n{0}",
                System.Text.Encoding.ASCII.GetString(responseArray));

When i do this, the remote server returns 405 Method not allowed.

Can anyone help? Please?

Pages: 1