2017-09-23 7 views
0

マルチパート/混合リクエストをazure Direct Batch Send(https://msdn.microsoft.com/en-us/library/azure/mt734910.aspx)に送信しようとしています。私はnpm要求モジュールを使用しています。私は形成したいどのような要求nodejsでマルチパート/混合リクエストを送信

: - 私が試してみました

POST https://{Namespace}.servicebus.windows.net/{Notification Hub}/messages/$batch?direct&api-version=2015-08 HTTP/1.1 
Content-Type: multipart/mixed; boundary="simple-boundary" 
Authorization: SharedAccessSignature sr=https%3a%2f%2f{Namespace}.servicebus.windows.net%2f{Notification Hub}%2fmessages%2f%24batch%3fdirect%26api-version%3d2015-08&sig={Signature}&skn=DefaultFullSharedAccessSignature 
ServiceBusNotification-Format: gcm 
Host: {Namespace}.servicebus.windows.net 
Content-Length: 431 
Expect: 100-continue 
Connection: Keep-Alive 


--simple-boundary 
Content-Type: application/json 
Content-Disposition: inline; name=notification 

{"data":{"message":"Hello via Direct Batch Send!!!"}} 
--simple-boundary 
Content-Type: application/json 
Content-Disposition: inline; name=devices 

['Device Token1','Device Token2','Device Token3'] 
--simple-boundary-- 

何: -

最初のアプローチ: -

Request({ 
      method: 'POST', 
      uri:'https://{namespace}.servicebus.windows.net/{Notification Hub}/messages/$batch?direct&api-version=2015-08', 
      headers: { 
       Authorization, 
     'Content-Type': 'multipart/mixed; ', 
       'ServiceBusNotification-Format': 'gcm', 
       'x-ms-version': '2015-04' 
      }, 
      multipart: [{ 
       'content-type': 'application/json', 
       body: { 
        data:{"message":"Hello via Direct Batch Send!!!"} 
       } 
      }, { 
       'content-type': 'application/json', 
       body : handles // This is array 
      }] 
     }, (err, res, body) => { 
      console.log('res: ', err, res, body) 
     } 

エラー: - 最初の引数は、文字列でなければなりませんバッファ、ArrayBuffer、配列、または配列のようなオブジェクト

2番目のアプローチ: -

 var formData = { 
      data:{"message":"Hello via Direct Batch Send!!!"}, 
      devices: handles // This is array 
     } 
     var options = { 
     uri:'https://{namespace}.servicebus.windows.net/{Notificatin Hub}/messages/$batch?direct&api-version=2015-08', 
     headers: { 
        Authorization, 
      'Content-Type': 'multipart/mixed; ', 
        'ServiceBusNotification-Format': 'gcm', 
        'x-ms-version': '2015-04' 
     } 
     } 
     Request.post({options, formData}, (err, res, body) => { 
      console.log('res: ', err, res, body) 
     }) 

エラー:options.uriは必須の引数

である私にサービスを直接送信する送信バッチを紺碧する混合/マルチパートリクエストを送信するために正しいとより良いアプローチを提案してください。参照詳細については、

multipart: [ 
    { 
    'content-type': 'application/json', 
    body: JSON.stringify({data: {"message": "Hello via Direct Batch Send!!!"}}) 
    }, 
    { 
    'content-type': 'application/json', 
    body : JSON.stringify(handles) 
    } 
] 

を:あなたはmultipartapplication/jsoncontent-typeを設定して、あなたの最初のアプローチでは、あなた

+0

最初のアプローチでは、バッファ内のハンドルに変換されます。 const buf1 =新しいバッファ(ハンドル)。 –

+0

Hey @PankajJatavはハンドルをバッファーに変更しました。bufferHandle =新しいバッファー(ハンドル)と本体のbufferHandleを渡しましたが、エラーで戻ってきました。要求からマルチパート・コンテンツを読み取れませんでした。 –

答えて

関連する問題