title: Changing RESTSharp POST code to .NET HttpClient
body: <p>I'm struggling a bit with a RestSharp POST request which I need to change to use HttpClient instead. It's quite a special case where I need to send some HTML markup to <a href="https://memsource.com" rel="nofollow noreferrer">Memsource</a> to create a new translation job. I've got it working in Postman where I am able to get the code example as a RestSharp request, but in my codebase, I'm using HttpClient.</p>
  
  <p>The RestSharp code example in Postman looks like this:</p>
  
  <pre><code>var client = new RestClient("https://cloud.memsource.com/web/api2/v1/projects/&lt;myProjectId&gt;/jobs?token=&lt;myAuthToken&gt;");
  client.Timeout = -1;
  
  var request = new RestRequest(Method.POST);
  
  request.AddHeader("Content-Disposition", "filename=\"translation.html\"");
  request.AddHeader("Memsource", "{\"targetLangs\": [\"da\", \"de\", \"de-AT\", \"de-BE\"]}");
  request.AddHeader("Content-Type", "application/octet-stream");
  
  request.AddParameter("application/octet-stream", "&lt;!doctype html&gt;\r\n&lt;html lang=\"en\"&gt;\r\n&lt;head&gt;\r\n  
  &lt;meta charset=\"utf-8\"&gt;\r\n  &lt;title&gt;My page&lt;/title&gt;\r\n  &lt;meta name=\"viewport\" 
  content=\"width=device-width, initial-scale=1\"&gt;\r\n&lt;/head&gt;\r\n&lt;body&gt;\r\n\t&lt;h1&gt;My page&lt;/h1&gt;\r\n\t&lt;p&gt;This is a paragraph&lt;br /&gt;That needs to be translated&lt;/p&gt;\r\n&lt;/body&gt;\r\n&lt;/html&gt;",  ParameterType.RequestBody);
  
  IRestResponse response = client.Execute(request);
  
  Console.WriteLine(response.Content);
  </code></pre>
  
  <p>My attempt with HttpClient is currently this:</p>
  
  <pre><code>string previewMarkup = "" // omitted markup for readability in this post
  
  var targetLangs = new { targetLangs = new[] { "da", "de", "de-AT", "de-BE" } };
  string targetLanguagesParamJson = JsonConvert.SerializeObject(targetLangs);
  
  HttpContent httpContent = new StringContent(previewMarkup, Encoding.UTF8, MediaTypeNames.Text.Html);
  
  httpContent.Headers.Add("Content-Disposition", "filename=\"translation.html\"");
  httpContent.Headers.Add("Memsource", targetLanguagesParamJson);
  httpContent.Headers.ContentType = MediaTypeHeaderValue.Parse(MediaTypeNames.Application.Octet);
  
  HttpResponseMessage httpResponseMessage = await _httpClient.PostAsync("https://cloud.memsource.com/web/api2/v1/projects/&lt;myProjectId&gt;/jobs?token=&lt;myAuthToken&gt;", httpContent, cancellationToken);
  </code></pre>
  
  <p>I keep getting the following error: <code>The format of value 'filename="translations.html"' is invalid.</code></p>
  
  <p>Does anyone know, what I might be missing here?</p>
  
  <p>Thanks in advance.</p>