Sendgrid入站Webhook发送空体

时间:2016-03-27 22:26:33

标签: meteor sendgrid

尝试按照说明here

获取Sendgrid的入站解析Webhook

使用Meteor和Iron路由器。我正在捕获请求,但请求正文是空的。我正在学习本教程https://sendgrid.com/blog/receive-inbound-email-meteorjs/https://sendgrid.com/blog/control-home-lighting-parse-webhook/,但是当我执行console.log(this.request.body)时,它返回一个空对象{}。

我也尝试过将文本(this.request.text),html,from,to,subject,但没有。我唯一获得成功的是this.request.headers。

Sendgrid活动仪表板确实显示正在解析电子邮件,我显然正在接收它们,但正文是空的。这是意外的行为,我不知道如何排除故障。任何人都能指出我正确的方向吗?谢谢。这是一个示例请求。

    { _readableState: 
    { highWaterMark: 16384,
      buffer: [],
      length: 0,
      pipes: null,
      pipesCount: 0,
      flowing: false,
      ended: false,
      endEmitted: false,
      reading: false,
      calledRead: false,
      sync: true,
      needReadable: false,
      emittedReadable: false,
      readableListening: false,
      objectMode: false,
      defaultEncoding: 'utf8',
      ranOut: false,
      awaitDrain: 0,
      readingMore: false,
      decoder: null,
      encoding: null },
   readable: true,
   domain: null,
   _events: { close: [Function] },
   _maxListeners: 10,
   socket: 
    { _connecting: false,
      _handle: 
       { fd: 34,
         writeQueueSize: 0,
         owner: [Circular],
         onread: [Function: onread],
         reading: true },
      _readableState: 
       { highWaterMark: 16384,
         buffer: [],
         length: 0,
         pipes: null,
         pipesCount: 0,
         flowing: false,
         ended: false,
         endEmitted: false,
         reading: true,
         calledRead: true,
         sync: false,
         needReadable: true,
         emittedReadable: false,
         readableListening: false,
         objectMode: false,
         defaultEncoding: 'utf8',
         ranOut: false,
         awaitDrain: 0,
         readingMore: false,
         decoder: null,
         encoding: null },
      readable: true,
      domain: null,
      _events: 
       { end: [Object],
         finish: [Function: onSocketFinish],
         _socketEnd: [Function: onSocketEnd],
         drain: [Object],
         timeout: [Function],
         error: [Function],
         close: [Object] },
      _maxListeners: 10,
      _writableState: 
       { highWaterMark: 16384,
         objectMode: false,
         needDrain: false,
         ending: false,
         ended: false,
         finished: false,
         decodeStrings: false,
         defaultEncoding: 'utf8',
         length: 0,
         writing: false,
         sync: true,
         bufferProcessing: false,
         onwrite: [Function],
         writecb: null,
         writelen: 0,
         buffer: [],
         errorEmitted: false },
      writable: true,
      allowHalfOpen: true,
      onend: [Function],
      destroyed: false,
      bytesRead: 8249,
      _bytesDispatched: 0,
      _pendingData: null,
      _pendingEncoding: '',
      server: 
       { domain: null,
         _events: [Object],
         _maxListeners: 10,
         _connections: 1,
         connections: [Getter/Setter],
         _handle: [Object],
         _usingSlaves: false,
         _slaves: [],
         allowHalfOpen: true,
         httpAllowHalfOpen: false,
         timeout: 5000,
         _connectionKey: '4:0.0.0.0:23683' },
      _idleTimeout: 5000,
      _idleNext: 
       { _connecting: false,
         _handle: [Object],
         _readableState: [Object],
         readable: true,
         domain: null,
         _events: [Object],
         _maxListeners: 10,
         _writableState: [Object],
         writable: true,
         allowHalfOpen: false,
         onend: null,
         destroyed: false,
         bytesRead: 79134,
         _bytesDispatched: 14036,
         _pendingData: null,
         _pendingEncoding: '',
         _idleTimeout: 30000,
         _idleNext: [Object],
         _idlePrev: [Circular],
         _idleStart: 1459115857090,
         _monotonicStartTime: 543430569,
         pipe: [Function],
         addListener: [Function: addListener],
         on: [Function: addListener],
         pause: [Function],
         resume: [Function],
         read: [Function],
         _consuming: true },
      _idlePrev: { _idleNext: [Circular], _idlePrev: [Object] },
      _idleStart: 1459115857771,
      _monotonicStartTime: 543431251,
      parser: 
       { _headers: [],
         _url: '',
         onHeaders: [Function: parserOnHeaders],
         onHeadersComplete: [Function: parserOnHeadersComplete],
         onBody: [Function: parserOnBody],
         onMessageComplete: [Function: parserOnMessageComplete],
         socket: [Circular],
         incoming: [Circular],
         maxHeaderPairs: 2000,
         onIncoming: [Function] },
      ondata: [Function],
      _paused: false,
      _httpMessage: 
       { domain: null,
         _events: [Object],
         _maxListeners: 10,
         output: [],
         outputEncodings: [],
         writable: true,
         _last: false,
         chunkedEncoding: false,
         shouldKeepAlive: true,
         useChunkedEncodingByDefault: true,
         sendDate: true,
         _headerSent: false,
         _header: '',
         _hasBody: true,
         _trailer: '',
         finished: false,
         _hangupClose: false,
         socket: [Circular],
         connection: [Circular],
         _headers: [Object],
         _headerNames: [Object],
         write: [Function],
         end: [Function] } },
   connection: 
    { _connecting: false,
      _handle: 
       { fd: 34,
         writeQueueSize: 0,
         owner: [Circular],
         onread: [Function: onread],
         reading: true },
      _readableState: 
       { highWaterMark: 16384,
         buffer: [],
         length: 0,
         pipes: null,
         pipesCount: 0,
         flowing: false,
         ended: false,
         endEmitted: false,
         reading: true,
         calledRead: true,
         sync: false,
         needReadable: true,
         emittedReadable: false,
         readableListening: false,
         objectMode: false,
         defaultEncoding: 'utf8',
         ranOut: false,
         awaitDrain: 0,
         readingMore: false,
         decoder: null,
         encoding: null },
      readable: true,
      domain: null,
      _events: 
       { end: [Object],
         finish: [Function: onSocketFinish],
         _socketEnd: [Function: onSocketEnd],
         drain: [Object],
         timeout: [Function],
         error: [Function],
         close: [Object] },
      _maxListeners: 10,
      _writableState: 
       { highWaterMark: 16384,
         objectMode: false,
         needDrain: false,
         ending: false,
         ended: false,
         finished: false,
         decodeStrings: false,
         defaultEncoding: 'utf8',
         length: 0,
         writing: false,
         sync: true,
         bufferProcessing: false,
         onwrite: [Function],
         writecb: null,
         writelen: 0,
         buffer: [],
         errorEmitted: false },
      writable: true,
      allowHalfOpen: true,
      onend: [Function],
      destroyed: false,
      bytesRead: 8249,
      _bytesDispatched: 0,
      _pendingData: null,
      _pendingEncoding: '',
      server: 
       { domain: null,
         _events: [Object],
         _maxListeners: 10,
         _connections: 1,
         connections: [Getter/Setter],
         _handle: [Object],
         _usingSlaves: false,
         _slaves: [],
         allowHalfOpen: true,
         httpAllowHalfOpen: false,
         timeout: 5000,
         _connectionKey: '4:0.0.0.0:23683' },
      _idleTimeout: 5000,
      _idleNext: 
       { _connecting: false,
         _handle: [Object],
         _readableState: [Object],
         readable: true,
         domain: null,
         _events: [Object],
         _maxListeners: 10,
         _writableState: [Object],
         writable: true,
         allowHalfOpen: false,
         onend: null,
         destroyed: false,
         bytesRead: 79134,
         _bytesDispatched: 14036,
         _pendingData: null,
         _pendingEncoding: '',
         _idleTimeout: 30000,
         _idleNext: [Object],
         _idlePrev: [Circular],
         _idleStart: 1459115857090,
         _monotonicStartTime: 543430569,
         pipe: [Function],
         addListener: [Function: addListener],
         on: [Function: addListener],
         pause: [Function],
         resume: [Function],
         read: [Function],
         _consuming: true },
      _idlePrev: { _idleNext: [Circular], _idlePrev: [Object] },
      _idleStart: 1459115857771,
      _monotonicStartTime: 543431251,
      parser: 
       { _headers: [],
         _url: '',
         onHeaders: [Function: parserOnHeaders],
         onHeadersComplete: [Function: parserOnHeadersComplete],
         onBody: [Function: parserOnBody],
         onMessageComplete: [Function: parserOnMessageComplete],
         socket: [Circular],
         incoming: [Circular],
         maxHeaderPairs: 2000,
         onIncoming: [Function] },
      ondata: [Function],
      _paused: false,
      _httpMessage: 
       { domain: null,
         _events: [Object],
         _maxListeners: 10,
         output: [],
         outputEncodings: [],
         writable: true,
         _last: false,
         chunkedEncoding: false,
         shouldKeepAlive: true,
         useChunkedEncodingByDefault: true,
         sendDate: true,
         _headerSent: false,
         _header: '',
         _hasBody: true,
         _trailer: '',
         finished: false,
         _hangupClose: false,
         socket: [Circular],
         connection: [Circular],
         _headers: [Object],
         _headerNames: [Object],
         write: [Function],
         end: [Function] } },
   httpVersion: '1.1',
   complete: false,
   headers: 
    { 'x-forwarded-proto': 'http',
      'x-forwarded-port': '80',
      'x-forwarded-for': '167.89.125.249,127.0.0.1',
      'content-type': 'multipart/form-data; boundary=xYzZY',
      'content-length': '8782',
      'user-agent': 'SendGrid 1.0',
      host: '6f496891.ngrok.io',
      connection: 'TE, close',
      te: 'deflate,gzip;q=0.3' },
   trailers: {},
   _pendings: [],
   _pendingIndex: 0,
   url: '/webhook/sendgrid',
   method: 'POST',
   statusCode: null,
   client: 
    { _connecting: false,
      _handle: 
       { fd: 34,
         writeQueueSize: 0,
         owner: [Circular],
         onread: [Function: onread],
         reading: true },
      _readableState: 
       { highWaterMark: 16384,
         buffer: [],
         length: 0,
         pipes: null,
         pipesCount: 0,
         flowing: false,
         ended: false,
         endEmitted: false,
         reading: true,
         calledRead: true,
         sync: false,
         needReadable: true,
         emittedReadable: false,
         readableListening: false,
         objectMode: false,
         defaultEncoding: 'utf8',
         ranOut: false,
         awaitDrain: 0,
         readingMore: false,
         decoder: null,
         encoding: null },
      readable: true,
      domain: null,
      _events: 
       { end: [Object],
         finish: [Function: onSocketFinish],
         _socketEnd: [Function: onSocketEnd],
         drain: [Object],
         timeout: [Function],
         error: [Function],
         close: [Object] },
      _maxListeners: 10,
      _writableState: 
       { highWaterMark: 16384,
         objectMode: false,
         needDrain: false,
         ending: false,
         ended: false,
         finished: false,
         decodeStrings: false,
         defaultEncoding: 'utf8',
         length: 0,
         writing: false,
         sync: true,
         bufferProcessing: false,
         onwrite: [Function],
         writecb: null,
         writelen: 0,
         buffer: [],
         errorEmitted: false },
      writable: true,
      allowHalfOpen: true,
      onend: [Function],
      destroyed: false,
      bytesRead: 8249,
      _bytesDispatched: 0,
      _pendingData: null,
      _pendingEncoding: '',
      server: 
       { domain: null,
         _events: [Object],
         _maxListeners: 10,
         _connections: 1,
         connections: [Getter/Setter],
         _handle: [Object],
         _usingSlaves: false,
         _slaves: [],
         allowHalfOpen: true,
         httpAllowHalfOpen: false,
         timeout: 5000,
         _connectionKey: '4:0.0.0.0:23683' },
      _idleTimeout: 5000,
      _idleNext: 
       { _connecting: false,
         _handle: [Object],
         _readableState: [Object],
         readable: true,
         domain: null,
         _events: [Object],
         _maxListeners: 10,
         _writableState: [Object],
         writable: true,
         allowHalfOpen: false,
         onend: null,
         destroyed: false,
         bytesRead: 79134,
         _bytesDispatched: 14036,
         _pendingData: null,
         _pendingEncoding: '',
         _idleTimeout: 30000,
         _idleNext: [Object],
         _idlePrev: [Circular],
         _idleStart: 1459115857090,
         _monotonicStartTime: 543430569,
         pipe: [Function],
         addListener: [Function: addListener],
         on: [Function: addListener],
         pause: [Function],
         resume: [Function],
         read: [Function],
         _consuming: true },
      _idlePrev: { _idleNext: [Circular], _idlePrev: [Object] },
      _idleStart: 1459115857771,
      _monotonicStartTime: 543431251,
      parser: 
       { _headers: [],
         _url: '',
         onHeaders: [Function: parserOnHeaders],
         onHeadersComplete: [Function: parserOnHeadersComplete],
         onBody: [Function: parserOnBody],
         onMessageComplete: [Function: parserOnMessageComplete],
         socket: [Circular],
         incoming: [Circular],
         maxHeaderPairs: 2000,
         onIncoming: [Function] },
      ondata: [Function],
      _paused: false,
      _httpMessage: 
       { domain: null,
         _events: [Object],
         _maxListeners: 10,
         output: [],
         outputEncodings: [],
         writable: true,
         _last: false,
         chunkedEncoding: false,
         shouldKeepAlive: true,
         useChunkedEncodingByDefault: true,
         sendDate: true,
         _headerSent: false,
         _header: '',
         _hasBody: true,
         _trailer: '',
         finished: false,
         _hangupClose: false,
         socket: [Circular],
         connection: [Circular],
         _headers: [Object],
         _headerNames: [Object],
         write: [Function],
         end: [Function] } },
   _consuming: false,
   _dumped: false,
   httpVersionMajor: 1,
   httpVersionMinor: 1,
   upgrade: false,
   originalUrl: '/webhook/sendgrid',
   _parsedUrl: 
    { protocol: null,
      slashes: null,
      auth: null,
      host: null,
      port: null,
      hostname: null,
      hash: null,
      search: null,
      query: null,
      pathname: '/webhook/sendgrid',
      path: '/webhook/sendgrid',
      href: '/webhook/sendgrid' },
   body: {},
 query: {} }

1 个答案:

答案 0 :(得分:2)

因此,Parse API向您选择的端点发出POST请求,但数据被编码为multipart / form-data。我建议使用Formidable这是一个快速中间件来解析数据,然后通过常规键值查找来提取它。这里有一些示例代码可以帮助您:

var form = new formidable.IncomingForm();
form.parse(req, function(err, fields, files){//do something here})