最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

[尝试通过快速js发布到API时获得'不支持的媒体类型'和'内部服务器错误']

网站源码admin17浏览0评论

[尝试通过快速js发布到API时获得'不支持的媒体类型'和'内部服务器错误']

[尝试通过快速js发布到API时获得'不支持的媒体类型'和'内部服务器错误']

我发生了非常奇怪的问题。基本上,我使用快递服务器作为代理,以防止在尝试使用Jira API时发生CORS问题。

我已创建添加附件端点,该端点应处理过帐多部分/表单数据。

问题是我得到

status: 415, statusText: 'Unsupported Media Type',

在回复中。我发现,每当我添加“ content-type”标头时,状态就会更改为500“内部服务器错误”,因此两者都会引起一些问题。

这是我的这条路线的代码:

app.post("/attachfile", multer().single("file"), async (req, res) => { console.log(req.file); // Req.file = // { // fieldname: 'file', // originalname: 'test.txt', // encoding: '7bit', // mimetype: 'text/plain', // buffer: <Buffer 31 32 33>, // size: 3 // } try { const response = await fetch( "http://localhost:8080/rest/api/latest/issue/DP-1/attachments", { method: "POST", body: req.file, headers: { Authorization: "Basic xxx", "X-Atlassian-Token": "no-check", }, } ); const result = await response.text(); console.log(response); //response while no content-type header: 'status: 415, message: 'Unsupported Media Type' //response with content-type header (multipart/form-data): 'status: 500, message: 'FileUploadException: the request was rejected because no multipart boundary was found' res.json(result); } catch (error) { console.log(error); } });

我发生了非常奇怪的问题。基本上,我使用快递服务器作为代理,以防止尝试使用Jira API时发生CORS问题。我创建了添加附件端点,......>
回答如下:尝试将'Content-Type': 'application/json',设置为标题的一部分

例如

发布评论

评论列表(0)

  1. 暂无评论