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:

7
  • is the behaviour the same if You're only posting like 1 character in your message ? Commented Jan 27, 2016 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... Commented Jan 27, 2016 at 20:17
  • according to their docs: no limit. the exception occurs on the line "var content = new FormUrlEncodedContent(postData);" Commented Jan 27, 2016 at 20:57
  • @Marty works fine with 1 char, or 2000 for that matter. only goes wrong for 65000+ messages Commented Jan 27, 2016 at 20:58
  • Could it be an issue with FormUrlEncodedContent class? Have a look at this answer stackoverflow.com/a/23740338/189738 Commented Jan 27, 2016 at 21:07

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

That is what second example does, isn't it?
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();

1 Comment

i am doing this keyvalue things... but still uri is still too long...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.