【问题标题】:POST request with text带有文本的 POST 请求
【发布时间】:2014-02-11 02:11:21
【问题描述】:

我遇到了一个奇怪的问题,对我来说似乎是正确的,嗯..我会尽力解释:

我的函数上传器:

var body = '<html>'+
'<head>'+
'<meta http-equiv="Content-Type" '+
'content="text/html; charset=UTF-8" />'+
'</head>'+
'<body>'+
'<form action="/upload" enctype="multipart/form-data" '+
'method="post">'+
'<input type="text" name="text" multiple="multiple">'+
'<input type="submit" value="Submit" />'+
'</form>'+
'</body>'+
'</html>';

response.writeHead(200, {"Content-Type": "text/html"});
response.write(body);
response.end();

和我的上传处理程序:

function upload(response, request) {
console.log("Request handler 'upload' was called.");

var form = new formidable.IncomingForm(),
fields = {};
console.log("about to parse");
response.writeHead(200, {"Content-Type": "text/html"});

response.write("You've sent the text: "+
    querystring.parse(request).text);


response.end(); 
}

我知道这是一个超级新手的问题,但是,这是怎么回事?大家能猜到吗?

上传任何文本时的结果是:未定义
有趣的是 Post 被捕获了,因为在解析之前它是一个对象..

【问题讨论】:

    标签: javascript node.js text http-post requesthandler


    【解决方案1】:

    在代码中,方法是POST。以下是问题:

    • querystring 没有为 POST 请求定义
    • multipart/form-data 不是必须的
    • multiple 不是 input type="text" 的必要属性

    【讨论】:

    • 感谢 Paul,已经有一段时间了,我发誓我现在是一个更好的程序员了。呵呵新年快乐:]
    • @rcBytes 很高兴知道。新年快乐。
    猜你喜欢
    • 2016-12-06
    • 2013-05-30
    • 1970-01-01
    • 1970-01-01
    • 2020-12-23
    • 2021-03-12
    • 2022-01-07
    • 2013-02-26
    • 1970-01-01
    相关资源
    最近更新 更多