Gere is my class so far:
using System;using System.Collections.Generic;using System.Net.Http;using System.Web;using System.Net;using System.IO;public class MyClass { private const string URL = "https://sub.domain.com/objects.json?api_key=123"; private const string data = @"{""object"":{""name"":""Title""}}"; public static void CreateObject() { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL); request.Method = "POST"; request.ContentType = "application/json"; request.ContentLength = data.Length; StreamWriter requestWriter = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII); requestWriter.Write(data); requestWriter.Close(); try { // get the response WebResponse webResponse = request.GetResponse(); Stream webStream = webResponse.GetResponseStream(); StreamReader responseReader = new StreamReader(webStream); string response = responseReader.ReadToEnd(); responseReader.Close(); } catch (WebException we) { string webExceptionMessage = we.Message; } catch (Exception ex) { // no need to do anything special here.... } } static void Main(string[] args) { MyClass.CreateObject(); }}
when I do csc filename.cs, I get the following error:
The type or namespace name 'Http' does not exist in the namespace 'System.Net' (are you missing an assembly reference?)
I'm using .NET 4.5