私はこのJavaコードを持っています
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpPostRequest = new HttpPost(URL);
StringEntity se;
se = new StringEntity(jsonObjSend.toString());
// Set HTTP parameters
httpPostRequest.setEntity(se);
httpPostRequest.setHeader("Accept", "application/json");
httpPostRequest.setHeader("Content-type", "application/json");
//httpPostRequest.setHeader("Accept-Encoding", "gzip");
// only set this parameter if you would like to use gzip compression
long t = System.currentTimeMillis();
HttpResponse response = (HttpResponse) httpclient.execute(httpPostRequest);
そしてこれはnode.jsにあります
var http = require('http');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
console.log("Entering");
if ( request.method === 'POST' ) {
// the body of the POST is JSON payload.
request.pipe(process.stdout);
}
});
// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);
// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");
パイプを使用してコンソールにすべてを書き込み、データを確実に受信できるようにします。私が実際に望んでいるのは、データを解析して JSON に戻し、それを配列に保存することです。リクエストからデータを取得するにはどうすればよいですか? 誰かがコード例を持っていますか?
ありがとう