空手道:在空手道v0.9.5中上传.xslx文件时出现403禁止错误 [英] Karate : 403 Forbidden error while uploading .xslx file in Karate v0.9.5

查看:34
本文介绍了空手道:在空手道v0.9.5中上传.xslx文件时出现403禁止错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个API,该API可以通过POST请求上传excel文件.

我正在尝试使用multipart file关键字上传"SampleFile.xlsx".

I am trying to upload a "SampleFile.xlsx" by using multipart file keyword.

多部分文件filename = {read:'SampleFile.xlsx',contentType:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',文件名:'SampleFile.xlsx'}

And multipart file filename = {read:'SampleFile.xlsx', contentType:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', filename:'SampleFile.xlsx'}

方法发布时

,还尝试将contentType更改为以下内容.

多部分文件filename = {read:'SampleFile.xlsx',contentType:'application/octet-stream',文件名:'SampleFile.xlsx'}

And multipart file filename = {read:'SampleFile.xlsx', contentType:'application/octet-stream', filename:'SampleFile.xlsx'}

方法发布时

标题信息:

内容处置:表单数据;名称=文件";文件名="SampleFile.xlsx" [\ r] [\ n]".POST调用期间还会使用CSRF令牌,JSESSIONID和特定于应用程序的身份验证参数.

"Content-Disposition: form-data; name="file"; filename="SampleFile.xlsx"[\r][\n]" . CSRF token, JSESSIONID and application specific authentication parameters are also used during the POST call.

同一应用程序的其他API可以与相同的cookie和标头一起正常工作.

Other APIs of the same application are working fine with same cookies and headers.

我们收到以下403错误.我们还观察到文件内容已转换为二进制文件.

内容传输编码:二进制[\ r] [\ n]"[main]调试org.apache.http.wire-http-outgoing-5 >>"/core.xmlPK [0x1] [0x2]-[0x0] [0x14] [0x0] [0x6] [0x0] [0x8] [0x0] [0x0] [0x0]![0x0] [0xc2] ^ Y [0x8] [0x90] [0x1] [0x0] [0x0] [0x1b] [0x3] [0x0] [0x0] [0x10] [0x0][0x0] [0x0] [0x0] [0x0] [0x0] [0x0] [0x0] [0x0] [0x0] [0x0] [0x0] [0x0] [0x10]/[0x0] [0x0] docProps/app.xmlPK [0x5] [0x6] [0x0] [0x0] [0x0] [0x0] [\ n][main] DEBUG org.apache.http.wire-http-outgoing-5<<"HTTP/1.1 403 Forbidden [\ r] [\ n]"

"Content-Transfer-Encoding: binary[\r][\n]" [main] DEBUG org.apache.http.wire - http-outgoing-5 >> "/core.xmlPK[0x1][0x2]-[0x0][0x14][0x0][0x6][0x0][0x8][0x0][0x0][0x0]![0x0][0xc2]^Y[0x8][0x90][0x1][0x0][0x0][0x1b][0x3][0x0][0x0][0x10][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0x10]/[0x0][0x0]docProps/app.xmlPK[0x5][0x6][0x0][0x0][0x0][0x0][\n]" [main] DEBUG org.apache.http.wire - http-outgoing-5 << "HTTP/1.1 403 Forbidden[\r][\n]"

相同的请求在Postman和Jmeter上也能正常工作.

The same request works fine on Postman and Jmeter.

请帮帮我!

谢谢.

(添加cURL代码以及我尝试过的所有可能方式)

(Adding cURL code and also all possible ways I tried)

—cURL from Chrome—

curl' https://samplexlsx.com/rest/upload '-H'Sec-提取模式:cors'-H'来源: https://samplexlsx.com '-H'接受编码:gzip,deflate,br'-H'接受语言:en-GB,en-US; q = 0.9,en; q = 0.8'-H'X-Requested-With:XMLHttpRequest'-H'Cookie:dslang = GB-EN;acn01-uat = XXXXX ==;acack-uat = XXXXXX;JSESSIONID = XXXXX.node0;xlsx_IT_srv_id = xxxxdd'-H'连接:保持活动状态'-H'用户代理:Mozilla/5.0(Macintosh; Intel Mac OS X 10_15_4)WebKit/537.36(KHTML,如Gecko)Chrome/77.0.3865.90 Safari/537.36'-H'内容类型:多部分/表单数据;boundary = ---- WebKitFormBoundaryeqxxxxx'-H'接受:application/json'-H'缓存控制:无缓存'-H'引用者:

curl 'https://samplexlsx.com/rest/upload' -H 'Sec-Fetch-Mode: cors' -H 'Origin: https://samplexlsx.com' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-GB,en-US;q=0.9,en;q=0.8' -H 'X-Requested-With: XMLHttpRequest' -H 'Cookie: dslang=GB-EN; acn01-uat=XXXXX==; acack-uat=XXXXXX; JSESSIONID=XXXXX.node0; xlsx_IT_srv_id=xxxxdd' -H 'Connection: keep-alive' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) WebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36' -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryeqxxxxx' -H 'Accept: application/json' -H 'Cache-Control: no-cache' -H 'Referer: https://samplexlsx.com/' -H 'Sec-Fetch-Site: same-origin' -H 'X-CSRF-Token: xxxxxxx+SjpXDA=' --data-binary $'------WebKitFormBoundaryeqxxxxx\r\nContent-Disposition: form-data; name="file"; filename="sample.xlsx"\r\nContent-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\r\n\r\n\r\n------WebKitFormBoundaryeqxxxxx--\r\n' ———compressed

-邮递员的网址-

curl --location --request POST' https://samplexlsx.com/rest/upload'\--header'X-CSRF-Token:xxxxxxx + SjpXDA ='\--header'X-Requested-With:XMLHttpRequest'\--header'推荐人: https://samplexlsx.com/'\--header'主持人:samplexlsx.com'\--header'Cookie:dslang = US-EN;acn01-uat = xxxxxxx ==;acack-uat = xxxxxxxdddd;JSESSIONID = xxxxxddd.node0'\--form'file = @/path/to/file'

curl --location --request POST 'https://samplexlsx.com/rest/upload' \ --header 'X-CSRF-Token: xxxxxxx+SjpXDA=' \ --header 'X-Requested-With: XMLHttpRequest' \ --header 'Referer: https://samplexlsx.com/' \ --header 'Host: samplexlsx.com' \ --header 'Cookie: dslang=US-EN; acn01-uat=xxxxxxx==; acack-uat=xxxxxxxdddd; JSESSIONID=xxxxxddd.node0' \ --form 'file=@/path/to/file’

解决方案列表:

#1.
Given url 'https://samplexlsx.com/rest/upload'
And def MultipartPayload = {}
And set MultipartPayload
  | path        | value                                                               |
  | read        | "classpath:testdata/sample.xlsx"                                    |
  | contentType | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' |
  | filename    | 'sample.xlsx'                                                       |
* def headerString1 = {  'Accept-Encoding': 'gzip, deflate, br', 'X-CSRF-Token' : 'xxxxddd', 'Content-Type': 'multipart/form-data', 'Host': 'samplexlsx.com', 'Origin': 'https://samplexlsx.com', 'Referer': 'https://samplexlsx.com/', 'X-Requested-With': 'XMLHttpRequest' , 'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) WebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36'}
And configure cookies = cookiesGen
And multipart file file = MultipartPayload
When method post

#2.
And def MultipartPayload = {}
And set MultipartPayload
  | path        | value                            |
  | read        | "classpath:testdata/sample.xlsx" |
  | contentType | 'application/octet-stream'       |
  | filename    | 'sample.xlsx'                    |
* def headerString1 = {  'Accept-Encoding': 'gzip, deflate, br', 'X-CSRF-Token' : 'xxxxddd', 'Content-Type': 'multipart/form-data', 'Host': 'samplexlsx.com', 'Origin': 'https://samplexlsx.com', 'Referer': 'https://samplexlsx.com/', 'X-Requested-With': 'XMLHttpRequest' , 'User-Agent' : 'Apache-HttpClient/4.5.5 (Java/11.0.1)'}
And configure cookies = cookiesGen
And multipart file file = MultipartPayload
When method post

#3.
And multipart field file = {read:'classpath:testdata/sample.xlsx', contentType:'application/octet-stream', filename:'sample.xlsx'}
* def headerString1 = {  'Accept-Encoding': 'gzip, deflate, br', 'X-CSRF-Token' : 'xxxxddd', 'Content-Type': 'multipart/form-data', 'Host': 'samplexlsx.com', 'Origin': 'https://samplexlsx.com', 'Referer': 'https://samplexlsx.com/', 'X-Requested-With': 'XMLHttpRequest' , 'User-Agent' : 'Apache-HttpClient/4.5.5 (Java/11.0.1)'}
And configure cookies = cookiesGen
When method post

#4.
And multipart file file = {read:'classpath:testdata/sample.xlsx', contentType:'application/octet-stream', filename:'sample.xlsx'}
* def headerString1 = {  'Accept-Encoding': 'gzip, deflate, br', 'X-CSRF-Token' : 'xxxxddd', 'Content-Type': 'multipart/form-data', 'Host': 'samplexlsx.com', 'Origin': 'https://samplexlsx.com', 'Referer': 'https://samplexlsx.com/', 'X-Requested-With': 'XMLHttpRequest' , 'User-Agent' : 'Apache-HttpClient/4.5.5 (Java/11.0.1)'}
And configure cookies = cookiesGen
When method post

#5.
And form field Content-Disposition = 'form-data'
And form field name = 'file'
And form field filename = 'sample.xlsx'
And form field Content-Type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
* def headerString1 = {  'Accept-Encoding': 'gzip, deflate, br', 'X-CSRF-Token' : 'xxxxddd', 'Content-Type': 'multipart/form-data', 'Host': 'samplexlsx.com', 'Origin': 'https://samplexlsx.com', 'Referer': 'https://samplexlsx.com/', 'X-Requested-With': 'XMLHttpRequest' , 'User-Agent' : 'Apache-HttpClient/4.5.5 (Java/11.0.1)'}
And configure cookies = cookiesGen
When method post

#6.
* def temp = karate.readAsString('classpath:testdata/sample.xlsx')
And multipart file file =  { value: '#(temp)', filename: 'sample.xlsx', contentType: 'text/xlsx' }
* def headerString1 = {  'Accept-Encoding': 'gzip, deflate, br', 'X-CSRF-Token' : 'xxxxddd', 'Content-Type': 'multipart/form-data', 'Host': 'samplexlsx.com', 'Origin': 'https://samplexlsx.com', 'Referer': 'https://samplexlsx.com/', 'X-Requested-With': 'XMLHttpRequest' , 'User-Agent' : 'Apache-HttpClient/4.5.5 (Java/11.0.1)'}
And configure cookies = cookiesGen
When method post

#7.
And bytes data = read('classpath:testdata/sample.xlsx')
And multipart file file = { value : '#(data)', filename: 'sample.xlsx', contentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'}
* def headerString1 = {  'Accept-Encoding': 'gzip, deflate, br', 'X-CSRF-Token' : 'xxxxddd', 'Content-Type': 'multipart/form-data', 'Host': 'samplexlsx.com', 'Origin': 'https://samplexlsx.com', 'Referer': 'https://samplexlsx.com/', 'X-Requested-With': 'XMLHttpRequest' , 'User-Agent' : 'Apache-HttpClient/4.5.5 (Java/11.0.1)'}
And configure cookies = cookiesGen
When method post

#8.
And multipart field read = "classpath:testdata/sample.xlsx"
And multipart field filename = 'sample.xlsx'
And multipart field contentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
* def headerString1 = {  'Accept-Encoding': 'gzip, deflate, br', 'X-CSRF-Token' : 'xxxxddd', 'Content-Type': 'multipart/form-data', 'Host': 'samplexlsx.com', 'Origin': 'https://samplexlsx.com', 'Referer': 'https://samplexlsx.com/', 'X-Requested-With': 'XMLHttpRequest' , 'User-Agent' : 'Apache-HttpClient/4.5.5 (Java/11.0.1)'}
And configure cookies = cookiesGen
When method post

#9.
And multipart entity read('classpath:testdata/sample.xlsx')
* def headerString1 = {  'Accept-Encoding': 'gzip, deflate, br', 'X-CSRF-Token' : 'xxxxddd', 'Content-Type': 'multipart/form-data', 'Host': 'samplexlsx.com', 'Origin': 'https://samplexlsx.com', 'Referer': 'https://samplexlsx.com/', 'X-Requested-With': 'XMLHttpRequest' , 'User-Agent' : 'Apache-HttpClient/4.5.5 (Java/11.0.1)'}
And configure cookies = cookiesGen
When method post

错误日志:错误日志

推荐答案

现在已解决.标头中的"CSRF-Token"已与另一个符号连接在一起.在开发人员的帮助下对其进行了调试.

This is resolved now. "CSRF-Token" in header was concatenated with another symbol. Debugged it with the help of developers .

这篇关于空手道:在空手道v0.9.5中上传.xslx文件时出现403禁止错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆