nodejs-connect-rest-sample icon indicating copy to clipboard operation
nodejs-connect-rest-sample copied to clipboard

Unable to read JSON request payload.

Open FreedomPaul opened this issue 9 years ago • 7 comments

I get the error : "{ "error": { "code": "BadRequest", "message": "Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.", "innerError": { "request-id": "c9608a1e-84c8-4aae-bb2c-09b7dc16ed8c", "date": "2017-02-04T14:37:28" } } }"

FreedomPaul avatar Feb 04 '17 16:02 FreedomPaul

Hi @FreedomPaul . Thanks for reporting this issue. When are you getting this error? Can you log in?

DianeD avatar Feb 04 '17 16:02 DianeD

Yes,I can log in. when I choose the Send Mail button,I get that error:BadRequest. I try to debug and I see that JSON.

FreedomPaul avatar Feb 04 '17 16:02 FreedomPaul

Thanks for the info. I wasn't able to repro the issue, so I'll ask the product team to look at your request in the service logs to see if they can help troubleshoot.

DianeD avatar Feb 04 '17 17:02 DianeD

Hi @DianeD . Today I find out the cause of that issue is Content-Length .

I suppose the emailAsPayload.Message.Body.content variable in this sample contains some Chinese characters because of my Office 365 account name when the sample is running.My Office 365 account name using my Chinese name.It causes that error:Unable to read JSON request payload.

I suddenly find a solution from the Internet and then I change some code , as follows: =================================================== In requestUtil.js file, changing the value of Content-Length:

function postSendMail(accessToken, mailBody, callback) { var outHeaders = { 'Content-Type': 'application/json', Authorization: 'Bearer ' + accessToken, ' Content-Length': Buffer.byteLength(mailBody,'utf8')//for utf-8 characters // 'Content-Length': mailBody.length//by default }; ... .... }//end =================================================== And then the sample runs successfully.Now I can send mail contains some Chinese characters!

FreedomPaul avatar Feb 05 '17 11:02 FreedomPaul

Thanks for letting us know! I'll make a note of this in the sample.

DianeD avatar Feb 05 '17 14:02 DianeD

Comment added. Thanks again @FreedomPaul !

DianeD avatar Feb 24 '17 21:02 DianeD

@DianeD So why not just replace the method? I don't think it will cause any unexpected problem.

iFwu avatar Oct 15 '18 03:10 iFwu