2

Trying to send a rather long string to a REST web api (youtrack). I get the following exception:

Invalid URI: The Uri string is too long.

My code:

var encodedMessage = HttpUtility.UrlEncode(message);
var requestUri = string.Format("{0}{1}issue/{2}/execute?comment={3}", url, YoutrackRestUrl, issue.Id, encodedMessage);
var response = await httpClient.PostAsync(requestUri, null).ConfigureAwait(false);

So I took my chances with a FormUrlEncodedContent

var requestUri = string.Format("{0}{1}issue/{2}/execute", url, YoutrackRestUrl, issue.Id);

var postData = new List<KeyValuePair<string, string>>();
postData.Add(new KeyValuePair<string, string>("comment", message));

var content = new FormUrlEncodedContent(postData);
var response = await httpClient.PostAsync(requestUri, content).ConfigureAwait(false);

Which results in the exact same issue.

The string (comment) I am sending, is the changed file set of a commit into SVN. Which can be really long, so I don't really have a way to get around that. Is there a way to post content without the string length restriction?

Read the following topics, but didn't find an answer there:

Community
  • 1
  • 1
bas
  • 13,550
  • 20
  • 69
  • 146
  • is the behaviour the same if You're only posting like 1 character in your message ? – Marty Jan 27 '16 at 20:15
  • It might be that you Youtrack api has a limmit on the 'comment' field. What does their API documentation say about that ? if there's a restriction on the comment property/field - then - not much You can do about it except than shorten it... – Marty Jan 27 '16 at 20:17
  • according to their docs: no limit. the exception occurs on the line "var content = new FormUrlEncodedContent(postData);" – bas Jan 27 '16 at 20:57
  • @Marty works fine with 1 char, or 2000 for that matter. only goes wrong for 65000+ messages – bas Jan 27 '16 at 20:58
  • Could it be an issue with `FormUrlEncodedContent` class? Have a look at this answer http://stackoverflow.com/a/23740338/189738 – adeel41 Jan 27 '16 at 21:07
  • can You post an full Http request that is being sent to the server ? with headers, urls ect.. You can easily capture it with Fiddler – Marty Jan 28 '16 at 10:20
  • @Marty, no need. Copy/pasted the `MyFormUrlEncodedContent` and it works like a charm. Many thx. Either drop it as answer, or I will look at your other answers and make sure you are properly rewarded for you help! :) – bas Jan 28 '16 at 10:52

2 Answers2

2

Well the short answer to it - just put it into the Body, instead of trying to push all the data via the URL

But as the work on the ticket showed - the answer was here How to set large string inside HttpContent when using HttpClient?

The actual problem beeing in the FormUrlEncodedContent

Community
  • 1
  • 1
Marty
  • 3,485
  • 8
  • 38
  • 69
0

Try this..Will be helpful for uwp..

 Uri uri = new Uri("your uri string");
 Windows.Web.Http.HttpClient client = new Windows.Web.Http.HttpClient();
 var value1 = new System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<string,string>>
 { 
     // your key value pairs
 };

 var response = await client.PostAsync(uri,new HttpFormUrlEncodedContent(value1));
 var result = await response.Content.ReadAsStringAsync();
Manikandan
  • 15
  • 7