Possible to Use C# to Simulate AngularJS login submission like Post? -


i see web page has <form name="formname" ng-submit=... , curious if there way log site c# .net.

i familiar using c# send "post" data including httpclient postasync, it's hard me search because every article talks angularjs controller or going angularjs page other page. getting pointed in right direction helpful!

post example found

var client = new httpclient(); var pairs = new list<keyvaluepair<string, string>>     {         new keyvaluepair<string, string>("pqpusername", "admin"),         new keyvaluepair<string, string>("password", "test@123")     }; var content = new formurlencodedcontent(pairs); var response = client.postasync("youruri", content).result; if (response.issuccessstatuscode) { } 

first of, wrap classes implement idisposible interface using statement. it's great feature , makes sure resource dispose method get's called when code done.

to make work, without knowing actual authentication type guess run bearer tokens here, need pass grant_type in url well.

try this

var postdata ="grant_type=password&pqpusername=admin&password=test@123";  using (var httpclient = new httpclient()) {     using (var content = new formurlencodedcontent(postdata))     {         content.headers.clear();         content.headers.add("content-type", "application/x-www-form-urlencoded");         var response = await httpclient.postasync("youruri", content);         var apiresponse = await response.content.readasasync<tresult>();     } } 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -