c# - Xamarin upload image to a REST web server (Bad Request) -




i know question has been posted more 1 time i’m still hanged problem of sending 1 image xamarin client rest web server. receive badrequest error on client side don’t know if comes server or client.

here xamarin code (client side) :

public class wsdest {    public string d_id { get; set; }    public string d_nom { get; set; }    public string d_cat1 { get; set; }    public string d_cat2 { get; set; }    public string d_annee { get; set; }    public byte[] d_photo1 { get; set; } }  static async task<string> do_updatevehiculeinfos(wsdest dest) {     string cret = "";     string cip = application.current.properties["ipserveur"].tostring().trim();       using (httpclient client = new httpclient())     {         try         {             var ojson = jsonconvert.serializeobject(dest);             var cjson = new stringcontent(ojson, encoding.utf8, "application/json");              client.defaultrequestheaders.accept.add(new system.net.http.headers.mediatypewithqualityheadervalue("application/json"));             client.timeout = timespan.frommilliseconds(8000);             client.maxresponsecontentbuffersize = 3000000;             client.baseaddress = new uri(cip + "/mywebservice.svc/");             using (httpresponsemessage r = await client.postasync("updatevehicule", cjson))             {                 if (r.issuccessstatuscode)                 {                     await application.current.mainpage.displayalert("", "mise à jour effectuée !", "+ok+");                     await application.current.mainpage.navigation.popasync(); //remove page on top (= retourne à la page d'avant)                 }                 else                 {                     await application.current.mainpage.displayalert("", r.reasonphrase.tostring(), "-ok-");                 }              }         }         catch (exception e)         {             await application.current.mainpage.displayalert("", e.message, "/ok/");         }     }     return cret; } 

on server side :

[datacontract] public class wsdest {     [datamember]     public string d_id { get; set; }     [datamember]     public string d_nom { get; set; }     [datamember]     public string d_cat1 { get; set; }     [datamember]     public string d_cat2 { get; set; }     [datamember]     public string d_annee { get; set; }     [datamember]     public byte[] d_photo1 { get; set; } }  [operationcontract] [webinvoke(method = "post", requestformat = webmessageformat.json, responseformat = webmessageformat.json, uritemplate = "updatevehicule")] bool updatevehicule(wsdest destupdate) ;    public bool updatevehicule(wsdest destrecep) {     // code process data , image } 

the badrequest message desapears when set dest.d_photo1 null on client side.

does have idea on subject?

can show how json looks byte having value?<<

before json.serializeobject(dest), dest.d_photos1 {byte[6855981]}. [137,80,70,....] after serialization, it's more 'exotic' :

before , after serialization

eric





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -