簡體   English   中英

android到http上的node.js

[英]android to node.js on http post

我發送到Android中的nodejs

這個 - -

    try {
        URL postUrl = new URL("http://192.168.25.36:9001/");
        HttpURLConnection con = (HttpURLConnection)postUrl.openConnection();
        con.setDoOutput(true);
        con.setInstanceFollowRedirects(false);
        con.setRequestMethod("POST");
        con.setRequestProperty("Content-Type", "application/json");

        OutputStream os = con.getOutputStream();
        os.write(jsonArray.toString().getBytes());
        os.flush();

        con.disconnect();
    } catch (IOException e) {
        e.printStackTrace();
    }

我認為它發送成功

因為當我發送郵件時,我的記錄器就是給我成功的

我的記錄器正在跟蹤此發送功能的開始和結束。

當我在端口上輸入錯誤(搜索如1234、9002)時,其無發送功能成功結束

但是為什么我的node.js服務器沒有動作?

我的node.js服務器是

這個 - -

var http = require('http');


http.createServer(function(req, res){
    console.log('server start');
    if("POST" == req.method){
        console.log('POST');
    }
}).listen(SERVER_PORT);

我認為當我開始使用node.js時

我在控制台上轉到“服務器啟動”

但是沒有一個詞是revv

這怎么可能?

我啟動node.js,但沒有“服務器啟動”消息

但是我的android發送功能正常結束

這是正確的嗎?

我不知道這是什么

我很抱歉

我自己成功

我的搜索不是永恆的

我修復我的代碼

android-

        DefaultHttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(URL);

        StringEntity entity = new StringEntity(jsonArray.toString(), HTTP.UTF_8);
        post.setEntity(entity);
        post.setHeader("Accept", "application/json");
        post.setHeader("content-type", "application/json");

        HttpResponse response = (HttpResponse)client.execute(post);

node.js-

var http = require('http');


var server = http.createServer(function(req, res){
    console.log('server start');
    if("POST" == req.method){
        console.log('POST');
        res.writeHead(200, {"Content-Type": "text/plain"});
        res.write("success");
        res.end();
    }
});

server.listen(SERVER_PORT); console.log(“服務器運行”);

謝謝〜

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM