小编Luc*_*enK的帖子

Node.js表示POST 404ing

我有一个使用快速框架的小node.js应用程序,但由于某种原因我无法让我的应用程序响应POST请求.在服务器日志中,我只是得到"POST/404 5ms",我无法弄清楚原因.

编辑:澄清 - 我的问题是app.post似乎没有做任何事情

编辑2:我昨晚设法解决了这个问题,但现在我无法弄清楚我修复了什么.

Node.js服务器代码:

var express = require('express')
  , routes = require('./routes')
  , user = require('./routes/user')
  , http = require('http')
  , path = require('path');

var app = express();

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('chocolatechip'));
app.use(express.session());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));


// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

//pages
//Landing page
app.get('/', routes.index);
app.post('/test',function(req,res){
  console.log(req.body);
  res.send("received post");
});
//return list containing users
//app.post('/users', user.list); …
Run Code Online (Sandbox Code Playgroud)

javascript post http-status-code-404 express backbone.js

5
推荐指数
1
解决办法
2万
查看次数

编译时c ++未定义的符号

修复:在头文件中有两次方法

尝试编译项目时出现以下错误

% make
g++ -o p4 testTree.o tree.o node.o check.o
Undefined                       first referenced
 symbol                             in file
Tree::inTree(int)                   tree.o
ld: fatal: Symbol referencing errors. No output written to p4
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `p4'
Run Code Online (Sandbox Code Playgroud)

Makefile文件

p4: testTree.o tree.o node.o check.o
    g++ -o p4 testTree.o tree.o node.o check.o
testTree.o: testTree.cc tree.h node.h check.h
    g++ -c -Wall -Werror testTree.cc

tree.o: tree.h tree.cc node.h check.h
    g++ -c -Wall -Werror tree.cc …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-errors makefile undefined-symbol

4
推荐指数
2
解决办法
3万
查看次数

ifstream总是将"ELF"返回给object

我编写了以下方法来检查我的程序是否与文件IO一起正常工作,但它绝对不起作用.我从inFile得到的只是"ELF",谁能告诉我为什么?我的对象与其他类型的istreams完美搭配.

void testFiles(int ct, char ** args)
{
    if(ct<2){
        cout<<"Invalid number of arguments. Must be two files, one for input, one for output."<<endl;
        return;
    }
    ifstream inFile;
    inFile.open(args[0]);
    Tree<Word,int> x;
    Word *key;
    Word *val;
    cout<<"Tree extracted from file: "<<endl;
    while(inFile.good()&&inFile.is_open()){
        key = new Word();
        val = new Word();
        inFile>>*key;
        inFile>>*val;
        if(!inFile.good()){
            cout<<"Error: incomplete key-value pair:"<<key->getStr()<<endl;
            break;
        }
        cout<<key->getStr()<<" "<<val->getStr()<<endl;
        x[*key] = val->asInt();
        delete key;
        delete val;
    }
    inFile.close();
    ofstream outFile;
    outFile.open(args[1]);
    cout<<"Tree as read from file:"<<endl<<x;
    outFile<<x;
    outFile.close();
}
Run Code Online (Sandbox Code Playgroud)

c++ io file-io fstream ifstream

1
推荐指数
1
解决办法
194
查看次数

使用std :: string.c_str()作为另一个方法的参数时的Segfault

谁能告诉我为什么使用来自c_str()的返回const char*作为stat(const char*,stat*)中的参数会导致程序出现段错误?我认为我已经将我的段错误缩小到由该行造成的,但我不确定要使用什么.我尝试使用strcpy()将字符串复制到字符数组中,但这只会导致程序在方法返回时出现段错误,这并不是更好.

DIR * dir_p;
struct dirent *dir_entry_p;
list<string> files;
dir_p = opendir(".");
//push all file names to a list
while((dir_entry_p = readdir(dir_p))!=NULL){
    string name = dir_entry_p->d_name;
    files.push_front(name);
}
closedir(dir_p);
files.sort();
//count total blocks
//iterate through list
map<string,struct  stat*> fileStats;
struct stat * entry;
for(list<string>::iterator it = files.begin(); it != files.end(); it++){
    stat(it->c_str(),entry);
    fileStats[*it]=entry;
    cout<<entry->st_blocks<<" "<<*it<<endl;
}
Run Code Online (Sandbox Code Playgroud)

c++ string stl stat

0
推荐指数
1
解决办法
1438
查看次数