The new company to work the next week, began to enter. Net Core, this aspect of things relatively new, so already packaged good things relatively few, such as Httpclien, such as Open source class library, find NuGet long, not found, so first write a humble to use first.
References:usingSystem.Threading.Tasks;usingSystem.Net.Http;usingNewtonsoft.json;usingSystem.Net.Http.Headers; Help class: Public Static classHttphelper { Public Static AsyncTask<t> get<t> (stringURL) { Try { using(varClient =NewHttpClient ()) { varResponsemsg =awaitclient. Getasync (URL); if(responsemsg.issuccessstatuscode) {stringStrjson =awaitResponseMsg.Content.ReadAsStringAsync (); returnJsonconvert.deserializeobject<t>(Strjson); } Else { return default(T); } } } Catch { return default(T); } } Public Static AsyncTask<t> post<t> (stringUrlDynamicpara) { Try { if(Para! =NULL) { varRequestjson =Jsonconvert.serializeobject (para); Httpcontent httpcontent=Newstringcontent (Requestjson); HttpContent.Headers.ContentType=NewMediatypeheadervalue ("Application/json"); using(varClient =NewHttpClient ()) { varResponsejson =awaitclient. Postasync (URL, httpcontent). Result.Content.ReadAsStringAsync (); returnJsonconvert.deserializeobject<t>(Responsejson); } } return default(T); } Catch { return default(T); } } }
To invoke the test:
=======================================================//  .----.// _. ' __ '.// .--(^) (^^)---/ #\// . ' @ /###\// : , #####// '-.. __.-' _.-\###/// ';_: ' '// . ' "" "" "" './/&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp; /, ya ,\\// //Up! 409 \\// '-._______.-'// ___ '. | . ' ___// (______|______)//====================== =================================
Httpclien get&post