Post data using MultipartFormDataContent from HttpClient
<p>I have a WebAPI service which reads post data including file data using </p>

<pre><code>HttpContext.Request as key value pairs
HttpContext.Current.Request["LoadId"]
</code></pre>

<p>Now I am trying to write and Console application using <code>HttpClient</code> but not able to make it work</p>

<pre><code>private static bool AddException(string vin, string loadId, string sessionId)
        {
            var client = new HttpClient
            {
                BaseAddress = new Uri("url")
            };
            ServicePointManager.ServerCertificateValidationCallback = (s, cert, chain, ssl) =&gt; true;

            const string quickCode = "01-01-1"; 
            const string inspectionType = "Loading";
            const string inspectorCode = "001";
            const string numberOfImages = "1";
            const string imageNumber = "1";
            const string exceptionType = "Driver";
            const string imageType = "exception";
            var date = DateTime.Now.ToString();

            var content = new MultipartFormDataContent();
            var values = new[]
                    {
                        new KeyValuePair&lt;string, string&gt;("LoadId", loadId),
                        new KeyValuePair&lt;string, string&gt;("VIN", vin),
                        new KeyValuePair&lt;string, string&gt;("SessionId", sessionId),
                        new KeyValuePair&lt;string, string&gt;("QuickCode", quickCode),
                        new KeyValuePair&lt;string, string&gt;("strInspectionType", inspectionType),
                        new KeyValuePair&lt;string, string&gt;("InspectorCode", inspectorCode),
                        new KeyValuePair&lt;string, string&gt;("NoOfImages", numberOfImages),
                        new KeyValuePair&lt;string, string&gt;("Imageno", imageNumber),
                        new KeyValuePair&lt;string, string&gt;("strExceptionType", exceptionType),
                        new KeyValuePair&lt;string, string&gt;("ImageType", imageType),
                        new KeyValuePair&lt;string, string&gt;("DateTimeOffset", date)
                    };
            var fileContent = new ByteArrayContent(File.ReadAllBytes(@"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg"));
            fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = "Desert.jpg"
            };
            content.Add(fileContent, "file", "11");

            foreach (var keyValuePair in values)
            {
                content.Add(new StringContent(keyValuePair.Value), keyValuePair.Key);
            }

            var response = client.PostAsync("Exception/AddException", content).Result;
            var exceptionResult = response.Content.ReadAsAsync&lt;bool&gt;().Result;

            return exceptionResult;
        }
</code></pre>

<p>The above is the code. But not able to read code from the service</p>

<p>I have no control over service code and cant change it</p>
