У нас есть API, который принимает запрос POST для загрузки файла Excel.
Я пытаюсь загрузить «SampleFile.xlsx», используя ключевое слово multipart file.
И составной файл filename = {читать: 'SampleFile.xlsx', contentType: 'application / vnd.openxmlformats-officedocument.spreadsheetml.sheet', имя файла: 'SampleFile.xlsx'}
Когда метод post
А также пытался изменить contentType на ниже.
И составной файл filename = {читать: 'SampleFile.xlsx', contentType: 'application / octet- stream ', filename:' SampleFile.xlsx '}
При публикации метода
Информация заголовков:
"Content-Disposition: form-data; name = "file"; filename = «SampleFile.xlsx" [\ r] [\ n] ". Токен CSRF, JSESSIONID и параметры аутентификации c приложения также используются во время вызова POST.
Другое API одного и того же приложения отлично работают с одинаковыми файлами cookie и заголовками.
Мы получаем ошибку 403, как показано ниже. Мы также заметили, что содержимое файла преобразовано в двоичный.
«Content-Transfer-Encoding: двоичный [\ r] [\ n]» [основная] DEBUG org. apache .http. провод - http-outgoing-5 >> «/core.xmlPK[0x1 provided[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] "[главная] DEBUG org. apache .http.wire - http-outgoing-5 <<" HTTP / 1.1 403 Запрещено [\ r] [\ n] " </p>
Тот же запрос отлично работает на Postman и Jmeter.
Пожалуйста, помогите мне!
Заранее спасибо.
РЕДАКТИРОВАТЬ: (Добавление кода cURL, а также все возможные способы, которые я пробовал)
—cURL from Chrome—
curl 'https://samplexlsx.com/rest/upload '-H' Se c -Fetch-Mode: cors '-H' Источник: 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' Cook ie: 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 Ma c OS X 10_15_4) WebKit / 537.36 (K HTML, как Gecko) Chrome / 77.0 .3865.90 Safari / 537.36 '-H' Content-Type: multipart / form-data; border = ---- WebKitFormBoundaryeqxxxxx '-H' Accept: application / json '-H' Cache-Control: no-cache '-H' Referer: https://samplexlsx.com/ '-H' Se c -Fetch-Site: same-origin '-H' X-CSRF-Token: xxxxxxx + SjpXDA = '--data-binary $' ------ WebKitFormBoundaryeqxxxxx \ r \ nContent-Disposition: form-data; name = "файл"; filename = «sample.xlsx» \ r \ nТип содержимого: application / vnd.openxmlformats-officedocument.spreadsheetml.sheet \ r \ n \ r \ n \ r \ n ------ WebKitFormBoundaryeqxxxxx - \ r \ n '——— сжатый
—cURL от Postman -
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 'Cook ie: dslang = US-EN; acn01-uat = xxxxxxx ==; acack-uat = xxxxxxxdddd; JSESSIONID = xxxxx ddd .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
Журнал ошибок: Журнал ошибок