0

Here is my code

var postData = "country=1";
postData += "&desktop_api=fsdf";
postData += "&adata=" + adData;
postData += "&about_page_data=" + aboutPageContent;
postData += "&url=" + url;

StringContent content = new StringContent("data=" + postData, Encoding.UTF8, "application/x-www-form-urlencoded");

HttpResponseMessage sResponse = await client.PostAsync(siteUrl, content).ConfigureAwait(false);

adData has over 2 million characters, but on my server I only receive around 2800 characters.

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
Arsh Kalsi
  • 179
  • 1
  • 10

1 Answers1

1

Url encoded post type is sometimes too limiting for a large amount of data, due to the fact it is one long url, using multipart form data solves this problem, this has previously been explained better then i can here : application/x-www-form-urlencoded or multipart/form-data?

without seeing the value of adData it would be difficult to tell you if you have a bad character that is causing issues. but for safety, you should ensure that your variables are UrlEncoded:

https://msdn.microsoft.com/en-us/library/system.web.httputility(v=vs.110).aspx

TLDR:

var postData = "country=1";

  postData += "&desktop_api=fsdf";
  postData += "&adata=" + HttpUtility.UrlEncode(adData);;
  postData += "&about_page_data=" + HttpUtility.UrlEncode(aboutPageContent);;
  postData += "&url=" + HttpUtility.UrlEncode(url);

OR

if you need a multipart example : C# HttpClient 4.5 multipart/form-data upload

Timtek
  • 65
  • 1
  • 7