I need to pass a byte array via a URL. So I am encoding it with the UrlEncode Method like this:
string ergebnis = HttpUtility.UrlEncode(array);
The result is the following string: %00%00%00%00%00%25%b8j
Now when I pass this string in a URL like this http://localhost:51980/api/Insects?Version=%00%00%00%00%00%25%b8j
This is my Get function:
public List<TaxonDiagnosis> Get([FromUri] string version)
{
List<TaxonDiagnosis> result = new List<TaxonDiagnosis>();
result = db.TaxonDiagnosis.ToList();
byte[] array = HttpUtility.UrlDecodeToBytes(version);
if (version != null)
result = db.GetTaxonDiagnosis(array).ToList();
return result;
}
The problem is, version's value isn't %00%00%00%00%00%25%b8j. Instead it is this \0\0\0\0\0%�j. This of course causes problems when I try to decode it into a byte array again.
How can I pass the correct string in the Url?
versionis already url-decoded. But it's kinda complicated to get bytes out of a string, due to encodings (as you can see %25%b8 ends up as a unicode character in your string). I don't have detailed knowledge about those web services...isn't it possible to change the method's argument fromstring versiontobyte[] array?