I am working on a project that requires the use of curl commands to load a file to a specific site. I want this to be implemented using C#. From looking at similar questions on SO I have not found anything that seems to work for me, unless I am doing this wrong.
This is the curl command I successfully use with Cygwin:
curl -i -u user:password -F 'file1=@\Users\User\Desktop\test.jpg' -F 'json={"content": {"type": "text/html", "text": "<body><p>look at me, look at me</p></body>"}, "type": "document", "subject": "Document with Attachment"};type=application/json' http://someurl
Right now I am trying to make this work with a WebRequest, as I've read that this was possible on other posts. This is what I have thus far.
WebRequest request = WebRequest.Create("http://someurl");
request.PreAuthenticate = true;
request.ContentType = "application/json";
request.Method = "POST";
string authInfo = Convert.ToBase64String(Encoding.UTF8.GetBytes("user:password"));
request.Headers["Authorization"] = "Basic " + authInfo;
//what do I set my buffer to?
Stream reqstr = request.GetRequestStream();
reqstr.Write(buffer, 0, buffer.Length);
reqstr.Close();
WebResponse response = request.GetResponse();
What do I set my buffer to here to write the curl command which in turn should send the file test.jpg? Also, I tried using libcurl without success either. Any pointers in the right direction are greatly appreciated!