POST请求与文本
我有一个奇怪的问题,这对我来说似乎是正确的,好吧..我会尽力解释:
我的function上传者:
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(); }
我知道这是一个超新手的问题,但是,发生了什么? 你们能猜到吗?
上传任何文本的结果是:undefined
有趣的事情正在被捕获,因为之前parsing它是一个对象..
在代码中,方法是POST。 这里是问题:
-
querystring
没有为POST请求定义 -
multipart/form-data
不是必需的 -
multiple
不是input type="text"
的必要属性