【问题标题】:Send xml file as payload in cypress post request在 cypress post 请求中发送 xml 文件作为有效负载
【发布时间】:2021-12-21 04:30:18
【问题描述】:

如何在 cypress post 请求中发送 xml 文件作为有效负载: 当我尝试将 xml 文件/txt 文件作为发布请求有效负载发送时,我无法做广告收到错误请求

【问题讨论】:

  • 您能添加一个您尝试过的代码示例吗?以及任何具体的错误信息?
  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: cypress


【解决方案1】:

这对我有用...(请原谅格式)

it('Post File to URL', () => {
    const yourFile = 'C:\\PathToYourFile\\YourFile.xml'
    cy
        .readFile(yourFile)
        .then(function (text) {
           cy.log(text)
           postXML(text)
        }
)})

function postXML(text) {
    return cy.request({
        url: 'https://yourURL.com',
        method: 'POST',
        body: text,
        headers: {
            'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'content-length': '1000',
            'connection': 'close',
            'soapAction': ''
        }
})}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-29
    • 1970-01-01
    • 2015-05-07
    • 1970-01-01
    • 2016-12-15
    • 1970-01-01
    • 2015-09-04
    • 1970-01-01
    相关资源
    最近更新 更多