Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am a newbie to working with Web Api and I am currently working with the Docusign web Api.
The webApi here requires to send the parameters as json or XML and I want to use Json here.
I am using HttpClient object for passing the credentials and calling the GetAsync() method of the HttpClient object the web APi.
The result of this call is processed using 'HttpResponseMessage'.


Now I want to call post and put methods.
So I will be using the the PostAsJsonAsync() and PutAsJsonAsync() functions.

I have created a Dictionary<string,>() object and I am adding the parameters and its values to it.
Then I am using,
string Jsonstring= JsonConvert.SerializeObject(DictionaryObject);
This gives me the Json as expected.

Now since I need to pass the json parameters along with the function calls.
Can anyone help me know how to pass the parameter.

Thanks in advance.
Posted

1 solution

Use

PostAsJsonAsync(requestUri, DictionaryObject)
 
Share this answer
 
Comments
shivprasads 29-May-13 6:49am    
Ohh!
I was just wondering if I did it wrongly, and yes I did it the same way! Thats right :)
Thanks a lot for the reply.

But now I am getting Content Type specified not supported error. :(
although I have specified the
httpclient1.DefaultRequestHeaders.Add("ContentType", "application/json;");
tumbledDown2earth 29-May-13 7:35am    
Can you post the json string of your sample object. Might help to resolve
shivprasads 29-May-13 8:32am    
below is the json string
{"currentPassword":"abcd123","email":"abc@example.com","newPassword":"987qwe"}


there is also one optional field that is not passed here.
or does that also needs to be passed as empty value?
tumbledDown2earth 29-May-13 12:22pm    
httpclient1.DefaultRequestHeaders.Add("Content-Type", "application/json;");

changed "ContentType" => "Content-Type"
shivprasads 30-May-13 2:22am    
thanks for the reply.

well that is something I already tried but it gives me an error at runtime that read:
"Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects."

Alteast "ContentTpe" was being accepted by DefaultRequestHeaders.Add() so I thought it may be more proper way of doing that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900