About how Node. js receives HttpPOST

Source: Internet
Author: User
Yes. Now we need to use Android to send an Httppost request to Node. js I tried to use PHP to receive Http requests in the past. It looks like this: {code ...} android is like this {code ...} however, in Node. what should I do with js? Does Node. js have a method similar to $ _ POST? Yes.
Now we need to use Android to send an Http post request to Node. js
In the past, I tried to use PHP to receive Http requests, which is like this:

$data = $_POST['data'];

Android is like this.

 HttpPost httpRequest = new HttpPost("192.168.1.174:3001"); List
  
    params = new ArrayList
   
    (); params.add(new BasicNameValuePair("data",etv.getText().toString())); try{    httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));    HttpResponse httpResponse = new DefaultHttpClient()                                    .execute(httpRequest);    if (httpResponse.getStatusLine().getStatusCode() == 200){        String strResult = EntityUtils.toString( httpResponse.getEntity() );        Log.d("HTTP", strResult);    } } catch (Exception e){   e.printStackTrace(); }
   
  

But what should I do in Node. js?
Does Node. js have a method similar to $ _ POST?

Reply content:

Yes.
Now we need to use Android to send an Http post request to Node. js
In the past, I tried to use PHP to receive Http requests, which is like this:

$data = $_POST['data'];

Android is like this.

 HttpPost httpRequest = new HttpPost("192.168.1.174:3001"); List
  
    params = new ArrayList
   
    (); params.add(new BasicNameValuePair("data",etv.getText().toString())); try{    httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));    HttpResponse httpResponse = new DefaultHttpClient()                                    .execute(httpRequest);    if (httpResponse.getStatusLine().getStatusCode() == 200){        String strResult = EntityUtils.toString( httpResponse.getEntity() );        Log.d("HTTP", strResult);    } } catch (Exception e){   e.printStackTrace(); }
   
  

But what should I do in Node. js?
Does Node. js have a method similar to $ _ POST?

We recommend that you use Express upstairs, so you can get a few lines of code.

Var http = require ("http"); var express = require ("express"); var app = express (); app. post ('/route_you_want', function (req, res) {// You can process post request res here. send ("hello world"); res. end () ;}); http. createServer (app ). listen (3000, function () {console. log ("server start ");});

Some of the post processing methods provided by the system are complicated. For details, Google recommends the web framework, such as express.

Using express alone is not very convenient. You can also try to addMulterMiddleware. I just tried it today. It's quite useful.

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.