[英]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.