Contents of the message received form the HttpPost
我在Node.js上运行Azure函数
到达的消息具有指定边界的内容类型。
'content-type': 'multipart/form-data;
boundary=------------------------8bb0bdeb26804014' },
如何获取RawRequest中找到的对象?
--------------------------8bb0bdeb26804014\r\nContent-Disposition: form data; name="rawRequest"\r\n\r\n
{"slug":"submit\\/80705882093865\\/",
"q1_nombres":"first":"textbox_sample0",
"last":"textbox_sample1"},
"q3_email":"john@example.com",
"preview":"true"}\r\n
EDIT1:
到目前为止我这样做:
var parts = req.headers['content-type'].split('boundary=');
var boundary = parts[1];
context.log("Boundary: "+boundary);
var splitBody = req.body.split( boundary );
context.log("RawRequest: "+splitBody[8]);
但我仍然需要解决这个问题:
Content-Disposition: form-data; name="rawRequest"
{"slug":"submit\/80705882093865\/",
"q1_nombres":{"first":"textbox_sample0",
"last":"textbox_sample1"},
"q3_email":"john@example.com",
"preview":"true"} --
如果我开始进一步操纵字符串,它似乎很容易破裂。
答案 0 :(得分:0)
尝试substring()
方法来实现这个目标怎么样?
var indexStart = splitBody.indexOf('{');
var indexEnd = splitBody.lastIndexOf('}') + 1;
var rawRequest = str.substring(indexStart, indexEnd);
console.log(rawRequest);