About node. js receiving Http POST

Source: Internet
Author: User
That is true
Now you want to pass an Http post request to node. js with Android
I've tried to receive HTTP requests in PHP before, and it's like this:

$data = $_POST['data'];

That's the way Android is.

 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 am I supposed to do with node. js?
Does the node. JS Band have no similar $_post method?

Reply content:

That is true
Now you want to pass an Http post request to node. js with Android
I've tried to receive HTTP requests in PHP before, and it's like this:

$data = $_POST['data'];

That's the way Android is.

 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 am I supposed to do with node. js?
Does the node. JS Band have no similar $_post method?

Support the proposed use of express upstairs, a few lines of code can be done

var http = require("http");var express = require("express");var app = express();app.post('/route_you_want', function(req, res){    //你可以在这里处理post请求    res.send("hello world");    res.end();});http.createServer(app).listen(3000, function(){    console.log("server start");});

Yes, but the system comes with a more complex post processing method can Google recommend the use of web frameworks, such as Express

Express alone is not very convenient, the main topic can also try to add a call multer Middleware, today just tried, very 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.