d***@qq.com
d***@qq.com
  • 发布:2022-09-06 09:59
  • 更新:2022-09-06 13:13
  • 阅读:246

【报Bug】uni.request使用post提交xml参数时,无法正常提交

分类:uni-app

产品分类: uniapp/H5

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win 10

HBuilderX类型: 正式

HBuilderX版本号: 3.6.0

浏览器平台: Chrome

浏览器版本: 99.0.4844.84

项目创建方式: HBuilderX

示例代码:

const ttsres = await uni.request({
url: 'https://eastus.tts.speech.microsoft.com/cognitiveservices/v1',
method: 'POST',
headers: {
'Content-Type': 'application/ssml+xml',
'X-Microsoft-OutputFormat': 'riff-24khz-16bit-mono-pcm',
'User-Agent':'useragent',
'Authorization': 'Bearer '+result.token
},
contentType: 'text',
data: content,
});

操作步骤:

const ttsres = await uni.request({
url: 'https://eastus.tts.speech.microsoft.com/cognitiveservices/v1',
method: 'POST',
headers: {
'Content-Type': 'application/ssml+xml',
'X-Microsoft-OutputFormat': 'riff-24khz-16bit-mono-pcm',
'User-Agent':'useragent',
'Authorization': 'Bearer '+result.token
},
contentType: 'text',
data: content,
});

预期结果:

返回正常的结果

实际结果:

401,服务器端无法解析

bug描述:

使用uni.request,提交的data为xml结构,header中设置了'Content-Type': 'application/ssml+xml'。contentType不管设成什么,都没办法正常提交。

但是在云函数中使用uniCloud.httpclient.request,提交的xml结构放在content中,就能成功。

uni.request要如何来支持xml?

2022-09-06 09:59 负责人:无 分享
已邀请:
CODE_XU

CODE_XU

你可以看一下 request paylaod 是否已经带上 xml 数据,这可能是服务端的问题

d***@qq.com

d***@qq.com (作者)

payload中已包含了xml数据,
不是服务器端的问题。我在python端和node.js端都可以正常处理。
提交时headers已经设置了'Content-Type': 'application/ssml+xml',

但是用uni.request提交的请求里,变成了json

这是chrome里看到的request.headers

accept-encoding: gzip, deflate, br
accept-language: zh-CN,zh;q=0.9
content-length: 245
content-type: application/json
origin: http://localhost:3000
referer: http://localhost:3000/

佬马识途

佬马识途 - 80后IT哥

uni.request({  
    url,  
    header:{}//这里是header不是headers,不用加s  
})

要回复问题请先登录注册