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