In case you're looking for how to convert the file to a byte array for the postman request:
byte[] bytes = System.IO.File.ReadAllBytes(@"C:\temp\myFile.txt");
string bytesStr = string.Join(",", bytes);
This will result into a long string that looks like this:
"49,48,58,50,52,58,50,54,..."
And then use it in the postman request like so:
{
"FileBytes":[49,48,58,50,52,58,50,54],
"DeviceId": 12345
}
Answer from Milana on Stack OverflowIn case you're looking for how to convert the file to a byte array for the postman request:
byte[] bytes = System.IO.File.ReadAllBytes(@"C:\temp\myFile.txt");
string bytesStr = string.Join(",", bytes);
This will result into a long string that looks like this:
"49,48,58,50,52,58,50,54,..."
And then use it in the postman request like so:
{
"FileBytes":[49,48,58,50,52,58,50,54],
"DeviceId": 12345
}
Think your Webapi method needs [HttpPut]
[HttpPut]
[Route("api/Manifest/VerifyChain/")]
[ResponseType(typeof (VerifyManifestChainResponse))]
public IHttpActionResult PutVerifyManifestChain([FromBody] VerifyManifestChainRequest message)
{
//.....
}
and in postman your message body would be an array
{
"CalculatedMeasurement":[71,107,98],
"DeviceId": "afdghufsdjdf"
}
Well it's an invalid JSON object.
StreamData has to be either a string or an object with a key.
Try
{
"From":"donotreply@xxx.com",
"To":["abc@xxx.com"],
"Cc":["abc@xxx.com"],
"Bcc":["abc@xxx.com"],
"Subject":"Export",
"TemplateName":"Agent",
"EmailType":"Agent",
"Attachments":[{
"Name":"wifi.txt",
"Type":"txt",
"StreamData": "NzI5OTk4NzgxNg0KDQoxIG0tNjczDQoNCjJtLTExMjINCjRtLTE1NzENCjgtMjE4Mw0KDQoxMDYxDQoNCjUwMCBtb2RlbSByZWZ1bmRhYmxl"
}]
}
In the sending code Base64 encode the byte array into a string.
Firstly, asp.net core does not support post multiple parameters from body, you need put these parameters into a model then you could post them from body.
Then, what you did should be post from query. But it seems does not support byte[] from query.
- If you use JSON.NET, you could post
clientId,dtNameandappendfrom query and postdtValuesfrom body like below(Be sure your controller is declared with[ApiController]):

- If you use
System.Text.Json,withSytem.Text.Jsona byte array (byte[]) will be serialized as base64 string. They stated that they won't add support forbyte[]to be serialized as number array in a github issue.
Custom JsonConverter:
public class ByteArrayConverter : JsonConverter<byte[]>
{
public override byte[] Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
short[] sByteArray = JsonSerializer.Deserialize<short[]>(ref reader);
byte[] value = new byte[sByteArray.Length];
for (int i = 0; i < sByteArray.Length; i++)
{
value[i] = (byte)sByteArray[i];
}
return value;
}
public override void Write(Utf8JsonWriter writer, byte[] value, JsonSerializerOptions options)
{
writer.WriteStartArray();
foreach (var val in value)
{
writer.WriteNumberValue(val);
}
writer.WriteEndArray();
}
}
Register it:
services.AddControllers().AddJsonOptions(options =>
{
options.JsonSerializerOptions.Converters.Add(new ByteArrayConverter());
});
Test in Postman:

BTW, not sure what is your scenario, if you post the byte array is something like file(e.g: image or .doc or .xlx file), you could use IFormFile and add [FromForm] before the parameter. Both JSON.NET or System.Text.Json supports receive IFormFile, no need custom JsonConverter here:
[Route("Upload")]
public IActionResult Upload(int clientId, string dtName, [FromForm]IFormFile dtValues, bool append)
{
return Ok();
}
Post the data like below:

If you do not want to separately post them from query and body, you could put them into a model and post them from body.
Model:
public class TestModel
{
public int clientId { get; set; }
public string dtName { get; set; }
public byte[] dtValues { get; set; }
public bool append { get; set; }
}
Post in Postman:
Note: if you use System.Text.Json, you still need to custom JsonConverter like above option 2 I shared.

You have to pass array and not string.
dtValues : [37,80]