urlConnection.getOutputStream被卡住

时间:2018-09-22 14:48:04

标签: java node.js

我正在尝试构建将数据发布到node.js服务器的Java应用程序。

用于处理node.js中帖子的代码如下:

app.post('/login.html', function (req, res) {

    log.info(req.body);
    userName = req.body.name;
    pass = req.body.pass;
    ...
}

该Java应用程序看起来如下:

URL url;

HttpURLConnection urlConnection = null;
try {
    url = new URL("http://86.61.133.223/login.html:39083");

    urlConnection = (HttpURLConnection) url.openConnection();


    urlConnection.setReadTimeout(10000);
    urlConnection.setRequestProperty("Content-Type", "application/json");

    urlConnection.setConnectTimeout(15000);
    urlConnection.setRequestMethod("POST");
    urlConnection.setDoInput(true);
    urlConnection.setDoOutput(true);

    OutputStream os = urlConnection.getOutputStream();          
    Map<String, String> parameters = new HashMap<>();
    parameters.put("name", "root");
    parameters.put("pass", "123456");

    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));          
    writer.write(getParamsString(parameters));
    writer.flush();
    writer.close();
    os.close();         

} 

由于未知原因,我被卡住了:

OutputStream os = urlConnection.getOutputStream();

在node.js中,我没有发现任何连接尝试。

那么,为什么我会卡住,如何解决呢?

1 个答案:

答案 0 :(得分:2)

如果39083应该是您的URL的端口(我认为)。端口属于主机名而不属于URI:

url = new URL("http://86.61.133.223:39083/login.html");