RestAPI addFeature response in JSON

806
2
Jump to solution
01-15-2020 12:09 AM
PrashantKirpan
Occasional Contributor

Hi All,

I am using rest api to add features using c# HttpClient. My data is added successfully but i am getting response in html instead of JSON.

here is my sample code: 

 var client = new HttpClient();

client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded");
client.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "application/x-www-form-urlencoded");

var inputJson = JsonConvert.SerializeObject(featureOobj);

var parameters = new Dictionary<string, string> { { "features", inputJson } };
var encodedContent = new FormUrlEncodedContent(parameters);

HttpResponseMessage response = await client.PostAsync(url, encodedContent)

How to receive rest api response in JSON? 

Any help would be appreciated.

Regards,

Prashant 

0 Kudos
1 Solution

Accepted Solutions
RandyBurton
MVP Alum

To set the output format, use the "f" query parameter:

f=json

See Output formats for more information.

View solution in original post

2 Replies
RandyBurton
MVP Alum

To set the output format, use the "f" query parameter:

f=json

See Output formats for more information.

PrashantKirpan
Occasional Contributor

Thanks for the help Randy,

0 Kudos