Data interaction with the Nodejs API interface via HttpClient

Source: Internet
Author: User

A simple example of using httpclient post data to implement a login Nodejs service interface

    • Nodejs: Using EXPRESSJS + Body-parser to develop a simple login login service Interface

var express = require (' Express '),    Bodyparser = require (' Body-parser '); var app = Express (); App.use (Bodyparser.json ( {limit: ' 1MB '}); App.use (bodyparser.urlencoded ({extended:true, limit: ' 1MB '));//Login Interface > Http://127.0.0.1:3000/loginapp.post ('/ Login ', function (req,res) {    var username = req.body.username;    var password = Req.body.password;    Console.log (' username: ' + username + '; password: "+password);    Res.json ({"Message": ' Welcome to login ', ' status ': 19999});}); App.listen (, function () {Console.log (' server is running ');});

  

    • Create a new WPF project, add a button to the main form, and then write the button's Click event

Private void _btnpost_click_1 (object  sender, RoutedEventArgs e) {       New  HttpClient ();
 var postdata New string  ,        string >> ();
PostData. ADD (Newkeyvaluepair<string,string> ("username","Vison")); PostData. ADD (Newkeyvaluepair<string,string> ("Password","vison1987")); Httpcontent content=Newformurlencodedcontent (postdata); Client. Postasync ("Http://127.0.0.1:3000/login", content). ContinueWith ((posttask) ={posttask. Result.Content.ReadAsStringAsync (). ContinueWith (Result)={MessageBox.Show (result. Result.tostring ()); =>s output JSON format string{"Message": ' Welcome to login ', ' status ': 19999}
        
      });     
}

=+ test Complete.

Data interaction with the Nodejs API interface via HttpClient

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.