内容简介:今天工作的时候遇到一个坑,在客户端用nodejs给服务器发送HTTP请求,服务器老是报错:In the context of Data Services an unknown internal server error occurred经过服务器端调试发现,服务器根本就没有正确解析出这个请求的content-type。在postman里能工作的场景下,正确解析出的content-type是multipart/mixed:
今天工作的时候遇到一个坑,在客户端用nodejs给服务器发送HTTP请求,服务器老是报错:In the context of Data Services an unknown internal server error occurred
经过服务器端调试发现,服务器根本就没有正确解析出这个请求的content-type。在postman里能工作的场景下,正确解析出的content-type是multipart/mixed:
而我的nodejs代码里明明指定了这个content-type的啊?
经过一行行代码分析,最后发现问题出在第63行的json字段的值。我错误的赋成了true。
这个参数起什么作用?调试一下就知道了。如果为true,进入第403行。
如果请求内部有entity的content-type不是application/x-www-form-urlencoded, 则进入第1293行。
safeStringify的实现逻辑就是浏览器原生的JSON.stringify, 把应用程序传入的json对象序列化成字符串。但是我的代码里,传入request module的请求体是一个字符串,而json参数设的又是true,所以逻辑上就不对了。把这个json参数的值改为false后,一切正常。
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
以上所述就是小编给大家介绍的《nodejs request module里的json参数的一个坑》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Out of their Minds
Dennis Shasha、Cathy Lazere / Springer / 1998-07-02 / USD 16.00
This best-selling book is now available in an inexpensive softcover format. Imagine living during the Renaissance and being able to interview that eras greatest scientists about their inspirations, di......一起来看看 《Out of their Minds》 这本书的介绍吧!