asp.net mvc - MVC accessing external Web API using login credentials -


in need of accessing external web api passing along credentials in order access methods available. have included code below use in order attempt access web api. however, receive following error every time attempt access it:

"the underlying connection closed: not establish trust relationship ssl/tls secure channel."

what missing or doing wrong? have been circling around couple days , have tried couple different techniques continue same error. here 1 technique used.

 private static async task<string> getapitoken(string username, string password, string apibaseuri)     {         try         {             using (var client = new httpclient())             {                 //setup client                 client.baseaddress = new uri(apibaseuri);                 client.defaultrequestheaders.accept.clear();                 client.defaultrequestheaders.accept.add(new mediatypewithqualityheadervalue("application/json"));                  //setup login data                 var formcontent = new formurlencodedcontent(new[]             {                 new keyvaluepair<string,string>("username",username),                 new keyvaluepair<string,string>("password",password),             });                  //send request                 httpresponsemessage responsemessage = await client.postasync("token", formcontent);                  //get access token response body                 var responsejson = await responsemessage.content.readasstringasync();                 var jobject = jobject.parse(responsejson);                 return jobject.getvalue("access_token").tostring();             }         }         catch (exception ex)         {             return null;         }     } 

any appreciated.

thanks

there little bit of difference when using https vs http. question should give information need fix problem.

make https call using httpclient


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -