0

how i can send binary data with post metht to RESTful api?

i should upload document with restful api. the Description of the post Functions is.

The (binary)content of the file should be sent as POST data.

how i can do it?

i try with the code:

using RestSharp;
using System.Text;
using System.IO;
...
var client = new RestClient("https://myServer.com/rest/");
client.AddHandler("text/html", new RestSharp.Deserializers.JsonDeserializer());      
var contactsRequest = new RestRequest("Documents?f=1&name=file.jpg", Method.POST);
var bytes = File.ReadAllBytes(@"C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg");
contactsRequest.AddBody(bytes);
var contacts = client.Execute(contactsRequest);

but it throw Exeption

The '[' character, hexadecimal value 0x5B, cannot be included in a name.

El_L
  • 355
  • 2
  • 8
  • 22
  • the header in the response should say which kind of content is sent in the response's body. – Rafa Jul 03 '13 at 08:54
  • you can give me example? – El_L Jul 03 '13 at 09:26
  • Sorry, I don't know your framework, but this is more or less what you did here: client.AddHandler("text/html", new RestSharp.Deserializers.JsonDeserializer()); – Rafa Jul 03 '13 at 09:29
  • you can put maybe "application/text" or something like that. – Rafa Jul 03 '13 at 09:29
  • I don't know your classes, but I think you're telling the server that you will send him a "text/html" from a json object, but your're sending a byte array that represent an image... – Rafa Jul 03 '13 at 09:31
  • It looks like there is a Left Square Bracket somewhere it shouldn't be. – jay_t55 Jul 04 '13 at 04:44

0 Answers0