Reputation: 393
Dont know what i doing wrong, need to fill database with datas from my VSTO Outlook Addin.
jObjectbody.Add( new { mail_from = FromEmailAddress });
mail_from
is name of column in database, FromEmailAddress
is value from my Outlook Addin
How to send to API https://my.address.com/insertData
correctly ?
RestClient restClient = new RestClient("https://my.address.com/");
JObject jObjectbody = new JObject();
jObjectbody.Add( new { mail_from = FromEmailAddress });
RestRequest restRequest = new RestRequest("insertData", Method.POST);
restRequest.RequestFormat = DataFormat.Json;
restRequest.AddParameter("text/html", jObjectbody, ParameterType.RequestBody);
IRestResponse restResponse = restClient.Execute(restRequest);
error : Could not determine JSON object type for type <>f__AnonymousType0`1[System.String].
If i try this in Postman (POST->Body->raw->JSON) data are strored in database, except dont use value
just data.
{
"mail_from":"[email protected]"
}
thanks for any clue achieve success
Upvotes: 0
Views: 263
Reputation: 1258
You can use restRequest.AddJsonBody(jObjectbody);
instead of AddParameter
(which I believe adds a query string).
See the RestSharp AddJsonBody docs. They also mention to not use some sort of JObject
as it wont work, so you will probably need to update your type as well.
The below might work for you:
RestClient restClient = new RestClient("https://my.address.com/");
var body = new { mail_from = "[email protected]" };
RestRequest restRequest = new RestRequest("insertData", Method.POST);
restRequest.AddJsonBody(body);
IRestResponse restResponse = restClient.Execute(restRequest);
// extra points for calling async overload instead
//var asyncResponse = await restClient.ExecuteTaskAsync(restRequest);
Upvotes: 1