如何在空手道0.9.0版中上传CSV文件作为发布请求? [英] How to upload CSV file as a post request in Karate 0.9.0 version?
问题描述
我正在使用Karate 0.9.0版本,并且想使用csv文件上传数据.根据新的更新,它将数据转换为JSON.但是我的API支持csv文件格式的上传功能.如何在发布请求中上传csv文件而不将数据转换为json?
I am using Karate 0.9.0 version and I want to upload data using csv file. As per new update, it is converting data into JSON. But my API supports csv file format for upload function. How can I upload csv file in post request without converting data into json?
Given path 'xxx/upload'
And header Authorization = xxx
And header Content-Type = 'text/csv'
And request read('classpath:xxx.csv')
When method POST
Then status 202
P.S.此示例在空手道版本中使用:0.9.0.RC5
P.S. This example was working in Karate version: 0.9.0.RC5
推荐答案
谢谢,这的确是我们未曾想到的一个极端情况,但是您有2个很好的选择:
Thanks, that is indeed an edge case we hadn't thought of, but you have 2 options that will work nicely:
1)将您的CSV文件重命名为*.txt
1) rename your CSV file to *.txt
And request read('classpath:xxx.txt')
2)使用karate.readAsString()API
2) use the karate.readAsString() API
And request karate.readAsString('classpath:xxx.csv')
这篇关于如何在空手道0.9.0版中上传CSV文件作为发布请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!