c# - Post XML as "application/xml" instead of "text/xml" via RestSharp -
i'm hooking salesforce bulk api using restsharp.
when add object using addbody
:
var request = new restrequest( method.post); request.requestformat = dataformat.xml; request.addheader("x-sfdc-session", loginresult.sessionid); var ji = new jobinfo { operation = "insert", @object = "contact", contenttype = "csv" }; request.addbody(ji, xmlns);
salesforce rejects error message:
unsupported content type: text/xml
... presumably because behind scenes restsharp interpreting request.requestformat = dataformat.xml;
"text/xml".
by fiddling around salesforce api have discovered wants "application/xml" instead of "text/xml".
is there supported way make restsharp send "application/xml" instead?
from documentation here
requestbody
if parameter set, value sent body of request. 1 requestbody parameter accepted – first one.
the name of parameter used content-type header request.
so:
var ji = new jobinfo { operation = "insert", @object = "contact", contenttype = "csv" }; var jiserialized = /* serialize ji xml format */ request.addparameter(new parameter { name = "application/xml", type = parametertype.requestbody, value = jiserialized })
Comments
Post a Comment