1

I'm trying to pass a string with special characters to your web api but is giving error.

Below the line where I pass the values ​​pro web api:

 string listaParcelaSeparadoVirgula = null; foreach (var item in listaParcelas) { listaParcelaSeparadoVirgula = listaParcelaSeparadoVirgula + ";;" + item; } var result = HttpUtility.UrlEncode(listaParcelaSeparadoVirgula); var response = client.PostAsJsonAsync("api/LancamentoReceitaDespesa/AddLancamentoParcelar/" + result, lancamentoReceitaDespesa).Result; 

the result is a string variable with values ​​separated by ";;". Below the contents of the string:

 ";;aaaaa 1/2||10/01/2014|100,00||;;aaaaa 2/2||10/02/2014|100,00||" 

with UrlEncode:

"%3b%3baaaaa+1%2f2%7c%7c10%2f01%2f2014%7c100%2c00%7c%7c%3b%3baaaaa+2%2f2%7c%7c10%2f02%2f2014%7c100%2c00%7c%7c" 

Error:

{"Error while copying content to a stream."}

How can I pass these values ​​pro web api?

1
  • Why are you passing the value in the URL and in the body? Is that really necessary? I don't think it is the URI that is complaining, it is the JSON.Net serialization that is having a problem. Commented Jan 10, 2014 at 12:31

1 Answer 1

2

Well you could try encode value with base64 since in url you could have special symbols

 var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(result); var response = client.PostAsJsonAsync("api/LancamentoReceitaDespesa/AddLancamentoParcelar/" + System.Convert.ToBase64String(plainTextBytes), lancamentoReceitaDespesa).Result; 

then in web

public void AddLancamentoParcelar(string base64EncodedData) { var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData); var result = System.Text.Encoding.UTF8.GetString(base64EncodedBytes); } 

I am not sure if its the best solution but as you could have any symbol in url then its could be an solution.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.