2015-03-31 102 views
1

我試圖使用request爲nodejs發送浴池請求至GMail API。問題是,即使低谷我產生相同的查詢,如文檔,Gmail中總是400錯誤請求Google API爲批量請求返回400 BadRequest

應對這些都是我在JSON主體內容的

{ 'Content-Type': 'multipart/mixed; boundary=c2db2692-8877-4159-bf02-03e6c5d3ffbf', 
    authorization: 'Bearer MY_TOKEN', 
    'content-length': 231 } 

實例的形式頭

--c2db2692-8877-4159-bf02-03e6c5d3ffbf 
Content-Type: application/http 
Content-ID: <item1:[email protected]> 


GET /gmail/v1/users/[email protected]/messages/14c6c0c43e9bb16b 


--c2db2692-8877-4159-bf02-03e6c5d3ffbf-- 

有什麼建議,爲什麼會發生這種情況? 請求生成額外的幾個空格,並以小寫字母,但我不知道這是否是問題。的的NodeJS代碼

request({ 
    method: 'POST', 
    uri: 'https://www.googleapis.com/batch', 
    auth: { 
     bearer: key 
    }, 
    headers: { 
     'Content-Type': 'multipart/mixed' 
    }, 
    multipart: _.map(queries, function(query) { 
     return { 
     'Content-Type': 'application/http', 
     'Content-ID': "<item1:[email protected]>", 
     body: 'GET ' + query 
     } 
    }) 
    }, function(error, response, body) { 

    console.log(response.request.headers) 
    _.map(response.request.body, function(chunk) { 
     console.log(chunk.toString()) 
    }) 

    console.log(body) 

    }) 

UPD:這顯然是如何使我的節點調用的問題,通過HTTPTester發送相同的請求,一切運行良好

UPD2:決定使用單身漢,但我還沒有想通是什麼原因導致此問題明顯請求

回答

3

很難排除這樣的問題。我很可能會說這是下到空間。我有一個類似的問題,那是因爲請求主體由於結構而被視爲無效。

大寫或小寫頭不應該引起問題。

如果可以幫助我創建了一個節點模塊來創建批量請求:https://www.npmjs.com/package/batchelor。隨意使用它。

+0

我對batchelor有問題,它期望響應內容類型具有不總是存在的邊界字段(batchelor.js:170)。我現在要創建問題 – 2015-03-31 10:04:59

+1

實際上,庫本身沒有問題,只是在文檔中出錯 – 2015-03-31 10:13:10

相關問題