c# - HttpClient Post deserialize error on SalesForce RestApi -


i'm trying use httpclient post new account via salesforce restapi, i'm receiving following error:

message: "can not deserialize sobject out of value_string token @ [line:1, column:1]". errorcode: "json_parse_error".

i'm using same json webrequest , httpclient tests. webrequest, works well.

here code httpclient:

        var uri = "https://na15.salesforce.com/services/data/v27.0/sobjects/account";          var acc = new account();         acc.name = "restapihttpclient";          var ser = new javascriptserializer();         var json = ser.serialize(acc);          httpclient client = new httpclient();          client.defaultrequestheaders.add("authorization", "bearer " + binding.sessionheadervalue.sessionid);          var response = await client.postasjsonasync(uri, json);         var stringresponse = await response.content.readasstringasync();         console.writeline(stringresponse);  

the account class im serializing simple:

    private class account     {         public string name { get; set; }     } 

update:

i changed code use postasync besides postasjsonasync, added jsonformatter @ content , working. great know why postasjsonasync doesn't work.

system.net.http.formatting.mediatypeformatter jsonformatter =      new system.net.http.formatting.jsonmediatypeformatter();  system.net.http.httpcontent content =      new system.net.http.objectcontent<account>(acc, jsonformatter);  var response = await client.postasync(uri, content);  


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -