[chronojump] Added json-post script



commit 757d5154dddfe8c70dc6bb1cb6a716a231d163a4
Author: Xavier de Blas <xaviblas gmail com>
Date:   Sat Jan 17 01:00:00 2015 +0100

    Added json-post script

 testing-stuff/json_post.cs                         |   59 ++++++++++++++++++++
 {no-rdotnet => testing-stuff/no-rdotnet}/passToR.R |    0
 .../no-rdotnet}/passToR.cs                         |    0
 3 files changed, 59 insertions(+), 0 deletions(-)
---
diff --git a/testing-stuff/json_post.cs b/testing-stuff/json_post.cs
new file mode 100644
index 0000000..2b0cdb8
--- /dev/null
+++ b/testing-stuff/json_post.cs
@@ -0,0 +1,59 @@
+//Carles Pina
+//compile:  mcs json_post.cs /reference:System.Json.dll
+
+using System;
+using System.Net;
+using System.Web;
+using System.IO;
+using System.Json;
+
+public class HelloWorld
+{
+    static public byte[] readFile(string filePath)
+    {
+       return System.IO.File.ReadAllBytes(filePath); 
+    }
+
+    static public void Main()
+    {
+            string filePath = "/home/carles/ip.txt";
+
+            // Create a request using a URL that can receive a post. 
+            WebRequest request = WebRequest.Create ("http://chronojump.org:8080/api/backtrace";);
+            // Set the Method property of the request to POST.
+            request.Method = "POST";
+            // Create POST data and convert it to a byte array.
+            byte[] byteArray = readFile(filePath);
+            // Set the ContentType property of the WebRequest.
+            request.ContentType = "application/x-www-form-urlencoded";
+            // Set the ContentLength property of the WebRequest.
+            request.ContentLength = byteArray.Length;
+            // Get the request stream.
+            Stream dataStream = request.GetRequestStream ();
+            // Write the data to the request stream.
+            dataStream.Write (byteArray, 0, byteArray.Length);
+            // Close the Stream object.
+            dataStream.Close ();
+            // Get the response.
+            WebResponse response = request.GetResponse ();
+            // Display the status.
+            Console.WriteLine (((HttpWebResponse)response).StatusDescription);
+            // Get the stream containing content returned by the server.
+            dataStream = response.GetResponseStream ();
+            // Open the stream using a StreamReader for easy access.
+            StreamReader reader = new StreamReader (dataStream);
+            // Read the content.
+            string responseFromServer = reader.ReadToEnd ();
+            // Display the content.
+            Console.WriteLine (responseFromServer);
+            // Clean up the streams.
+            reader.Close ();
+            dataStream.Close ();
+            response.Close ();    
+
+
+            JsonValue result = JsonValue.Parse(responseFromServer);
+            string crash_id = result["crash_id"];
+            Console.WriteLine("crash_id: "+ crash_id);
+    }
+}
diff --git a/no-rdotnet/passToR.R b/testing-stuff/no-rdotnet/passToR.R
similarity index 100%
rename from no-rdotnet/passToR.R
rename to testing-stuff/no-rdotnet/passToR.R
diff --git a/no-rdotnet/passToR.cs b/testing-stuff/no-rdotnet/passToR.cs
similarity index 100%
rename from no-rdotnet/passToR.cs
rename to testing-stuff/no-rdotnet/passToR.cs


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]