c# - Passing values from controller to WebAPI -
i have need track emails , pages on our website. want use webapi this, new , examples found hard follow. here problem:
i have emailtrackercontoller code below:
public class emailtrackingcontroller : controller { [outputcache(nostore = true , duration = 0)] [httppost] public actionresult getpixel(string email, guid emailid) { var client = new httpclient(); var endpoint = "http://localhost:2640/api/emailtracker/saveemail"; --path api var response = await client.postasync(endpoint, null); --this not work const string cleargif1x1 = "r0lgodlhaqabaiaaap///waaach5baeaaaaalaaaaaabaaeaaaicraeaow=="; return new filecontentresult(convert.frombase64string(cleargif1x1) , "image/gif"); } }
i have created webapi has httppost method called saveemail:
[httppost] public httpresponsemessage saveemail([frombody]string value) { --how email , guid need here? var = new dl.emailtracking(); a.insert("<email>" , guid.newguid()); return request.createresponse(httpstatuscode.accepted , ""); }
couple of questions on this:
- how pass values controller webapi?
- any easy follow examples great, of if have link useful well.
the second parameter of postasync
content of call. serialize object json contains values want , add content.
var obj = new { email = "mail@mail.com" }; httpstringcontent msg = new httpstringcontent(jsonconvert.serializeobject(obj)); var response = await client.postasync(endpoint, msg);
modify receiving method receive desired properties. i'd use class methods parameter can use [frombody]
properties listed well.
public httpresponsemessage saveemail(emailsave model)
Comments
Post a Comment