In Spring Webflux, when I read a POST body, and try to work with it, it always results in the IllegalStateException from the title.
Here the code:
#Bean
public RouterFunction<ServerResponse> selectByPost(SasoSecurityFacade solrHandler) {
return RouterFunctions.route(RequestPredicates.POST("/v1/{collection}/select")
.and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), request -> request.bodyToMono(String.class)
.flatMap(s -> {
System.out.println(s);
return ServerResponse.ok()
.syncBody(s);
}));
}
Also important (as it turns out), the request TO the server:
curl 'https://<myserver>:9443/v1/banana-int/select' -H 'Pragma: no-cache' -H 'Origin: https://<myserver>:9443' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36' -H 'Content-type: application/x-www-form-urlencoded' -H 'Accept: application/json, text/plain, */*' -H 'Cache-Control: no-cache' -H 'Referer: https://<myserver>:9443/banana/src/index.html' -H 'Connection: keep-alive' -H 'DNT: 1' --data 'q=*:*&rows=20&wt=json' --compressed
What am I doing wrong? How can I debug this? Who else is reading my post body, so that I get this error message?
The request you're sending is a POST Form request, which is automatically read by HiddenHttpMethodFilter. This filter is consuming the form data to mutate the HTTP method in case an alternate method is specified through a "_method" parameter.
In this case, consuming the form data with the dedicated request.formData() API in WebFlux annotation/functional is the best choice, this it is cached for future use and does not trigger a new subscription.
If you wish to completely disable this behavior, you'll be able to set a property in Spring Boot 2.1.
Related
I'm trying to use POST methods (Revenue REST API) but I always get the error message "Content-Type not application/json".
The strange is that I'm using their website to test: [https://docs.revenuecat.com/reference#receipts][1]
API TEST (IMAGE)
curl --request POST \
--url https://api.revenuecat.com/v1/receipts \
--header 'Accept: application/json' \
--header 'Authorization: Bearer xxxx' \
--header 'Content-Type: application/json' \
--header 'X-Platform: android' \
--data '
{
"product_id": "xxxx",
"price": 12.9,
"currency": "BRL",
"is_restore": "false",
"app_user_id": "xxxx",
"fetch_token": "xxxxxx"
}
'
Any clues?
I've run the code using CURL and it works. Problem was in revenuecat website.
Their API test page has a bug. It adds an extra Content-Type: application/json
header to the request. You can see it the Metadata tab
Request Headers
Accept: application/json
Content-Type: application/json
X-Platform: stripe
Content-Type: application/json
Authorization: Bearer ********************
User-Agent: ReadMe-API-Explorer
And sends the request with an invalid header (you can check it in your browsers network traffic):
content-type: application/json, application/json
I'm trying to trigger "play" -funtion with spotify API and tcl/http.
Here is the concept, in curl: https://developer.spotify.com/console/put-play/
curl -X "PUT" "https://api.spotify.com/v1/me/player/play" --data "{\"context_uri\":\"spotify:album:5ht7ItJgpBH7W6vJ5BqpPr\",\"offset\":{\"position\":5},\"position_ms\":0}" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer "
Here's a working example with tcl using exec curl:
set url https://api.spotify.com/v1/me/player/play?device_id=$device_id
set data "{\"context_uri\":\"spotify:album:5ht7ItJgpBH7W6vJ5BqpPr\",\"offset\":{\"position\":5},\"position_ms\":0}"
if {[catch {
exec curl -X "PUT" "$url" --data $data -H "Accept: application/json" \
-H "Content-Type: application/json" -H "Authorization: Bearer $oauth"
} msg]} then {
puts $msg
}
But i'd like to do it with tcl/http, if it's possible.
Here is my best shot so far doing this with http, but it says "malformed json".
if {$incoming == ".play"} {
::http::register https 443 {::tls::socket -autoservername 1}
::http::config -urlencoding utf-8 -useragent {JSON curl/7.55. 1}
set spot_url [http::geturl https://api.spotify.com/v1/me/player/play? \
-method PUT \
-query {{device_id:"d70b1f06*MASKED*36c308",
"context_uri":"spotify:album:5ht7ItJgpBH7W6vJ5BqpPr","offset":{"position":5},"position_ms":0}} \
-headers [list Accept application/json Content-Type application/json Authorization "Bearer $::access_token"]]
set spot_temp [::http::data $spot_url]
::http::cleanup $spot_temp
::http::cleanup $spot_url
return $spot_temp
}
Any idea how to send it correct to avoid malformed json? :D
Thanks!
Short Version:
I use Node-RED automation to manage network.
Via Node-RED I query the Arris SB8200 Cable Modem to get connection and event status hourly and store in a database.
A recent Comcast modem firmware update forces usage of user/pw on the modem to retrieve status.
I have been unable to successfully authenticate and retrieve status via cURL but can do so from a browser.
I have googled and tried a dozen different cURL authentication approaches without success. There are 3 complicating factors:
Username/password authentication. I am assuming this is just basic auth and shouldn't be an issue but see #2.
There is a session cookie "credential" that must be maintained across requests. This shouldn't be a problem but no matter what I try no cookies are captured in my specified cookies.txt file.
A manual login (to https://192.168.100.1/) is immediately followed by a redirect (to https://192.168.100.1/cmconnectionstatus.html). When I try to use the chrome dev tools "save as cURL" only the redirect is available, not the initial login so I cannot capture the login cURL.
I am hoping somebody who reads this has cURL'd into an SB8200 cable modem (or similar) with user/pw authentication and can just post the details. More likely will be many suggestions of things to try and some google result links, most of which I likely tried already. What would be most helpful to start I think is troubleshooting why I cannot get a successful login and the credential cookie set on my initial cURL.
BTW - The username and password are known to me, were set by me, and work fine to login from a browser. I think no matter how I have passed in the credentials I am just being returned the login form again. Maybe basic auth will never work and I need to do something else.
EDIT: I discovered the "Preserve Log" option in Chrome dev tools. This allowed me to copy as curl both the login and the redirect actions. And running the login curl (which does use basic auth) does return me on stdout a credential cookie. I was not able to get this cookie stored in my cookies.txt file using the cookie options in curl. And immediately using the returned cookie in the redirect curl does not get me the expected results and instead returns the login page. But I am getting closer.
Here is the Chrome-captured cURL for the login and redirect from the browser:
curl 'https://192.168.100.1/cmconnectionstatus.html?<REDACTED>' \
-H 'Connection: keep-alive' \
-H 'sec-ch-ua: "Chromium";v="88", "Google Chrome";v="88", ";Not A Brand";v="99"' \
-H 'DNT: 1' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'Authorization: Basic <REDACTED>' \
-H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' \
-H 'Accept: */*' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36' \
-H 'X-Requested-With: XMLHttpRequest' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Accept-Language: en-US,en;q=0.9' \
-H 'Cookie: HttpOnly: true, Secure: true' \
--compressed \
--insecure
curl 'https://192.168.100.1/cmconnectionstatus.html' \
-H 'Connection: keep-alive' \
-H 'sec-ch-ua: "Chromium";v="88", "Google Chrome";v="88", ";Not A Brand";v="99"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'Upgrade-Insecure-Requests: 1' \
-H 'DNT: 1' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'Sec-Fetch-Mode: navigate' \
-H 'Sec-Fetch-User: ?1' \
-H 'Sec-Fetch-Dest: document' \
-H 'Accept-Language: en-US,en;q=0.9' \
-H 'Cookie: HttpOnly: true, Secure: true; credential=gmhyY4SjR3qiWBiNIOtivpj4TF5Zwad' \
--compressed \
--insecure
Here is the HTML document returned when I try to login:
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<script src="jquery-1.7.1.min.js"></script>
<script src="json2.js"></script>
<script src="main_arris.js"></script>
<script src="jquery-2.0.3.min.js"></script>
<script>
$(document).ready(function(){
$("#htmlheader").load("htmlheader.htm");
});
</script>
</head>
<body>
<div id="htmlheader"></div>
<div class="header">
<script>
$(document).ready(function(){
$("#pageheaderA").load("pageheaderA.htm");
});
</script>
<div id="binnacleWrapper1" class="binnacleItems_hide" style="display:none;">
<div id="binnacleWrapper2" class="binnacleItems_hide" style="display:none;">
<div id="binnacleWrapperLeft"><img src="px1_Ux.png" alt="" class="binnacleWrapperShim"></div>
<div id="binnacleWrapperRight"><img src="px1_Ux.png" alt="" class="binnacleWrapperShim"></div>
<div id="binnacleWrapperMiddle">
<div id="binnacleInnards">
<div id="binnacleIndicatorWrap"></div>
<div id="binnacleModelName">
<span id="thisModelNumberIs">
<label id="model">SB8200</label></span></div>
</div>
</div>
</div>
</div>
<div id="pageheaderA"></div>
<div class="container">
<div class="subHeader">
<div class="subHeadcontent">Login</div>
</div>
<form action="">
<br>
<b>Username:</b><br>
<input type="text" id="username" onkeypress="return checkForActivate(event)">
<br>
<br>
<b>Password:</b><br>
<input type="password" id="password" onkeypress="return checkForActivate(event)">
<br>
<br>
<input type="button" id="loginButton" onclick="validate(this.form)" value="Login">
</form>
</div>
<div class="spacer40" style="text-align: center; color: red; font-weight: bold;"></div>
<div class="spacer70"></div>
</div>
<!--gap<div id="bmtg"><div class="gap1"><div class="gap2"><div class="gap3"><div class="gap4"></div></div></div></div></div>-->
<div id="fg1"><div id="fg2"><div id="fg3"><div id="fg4"><div id="fg5"><div id="fg6"><div id="fg7">
<div id="logo_bottom"><img src="px1_Ux.png" alt="ARRIS" title="ARRIS" class="logo_bottom"></div>
<div id="copyright">
©CommScope, Inc. All rights reserved. ARRIS, SURFBOARD and SURFBOARD MAX are trademarks of CommScope, Inc.<br />All other trademarks are the property of their respective owners.
</div>
</div></div></div></div></div></div></div>
<!--/div-->
<script>
function authenticateUser(user, password)
{
var token = user + ":" + password;
// Base64 Encoding -> btoa
var hash = btoa(token);
var auth = hash;
sessionStorage.setItem('auth', auth);
return auth;
}
function validate( form )
{
$(".spacer40")[0].innerHTML = "";
authenticateUser(form.username.value, form.password.value);
localStorage.setItem('username', form.username.value);
eraseCookie("credential");
$.ajax({
type: 'GET',
url:"/cmconnectionstatus.html?" + sessionStorage.getItem('auth'),
contentType: 'application/x-www-form-urlencoded; charset=utf-8',
xhrFields: {
withCredentials: true
},
headers: {
'Authorization': 'Basic ' + sessionStorage.getItem('auth')
},
success: function (result) {
var token = result;
createCookie("credential", result);
window.location.href = "/cmconnectionstatus.html";
},
error: function (req, status, error) {
alert(error);
}
});
}
function checkForActivate( e )
{
if( e.keyCode == 13 )
{
document.getElementById("loginButton").click();
}
return true;
}
</script>
<!--/div-->
</body>
</html>
Solved it myself. Once I was able to save the login as curl in chrome, things fell in place. Looks like I was missing some required curl options in my initial attempts. I still need to skinny this down to the minimal necessary options, eliminate the double copy of user/pw chrome encoded, and add error checking. But the following will successfully login and pull modem status for an Arris SB8200. Never did get curl to store the credential cookie in a cookies.txt file so just used a local shell variable.
cookie=`curl 'https://192.168.100.1/cmconnectionstatus.html?<REDACTED>' -H 'Connection: keep-alive' -H 'sec-ch-ua: "Chromium";v="88", "Google Chrome";v="88", ";Not A Brand";v="99"' -H 'DNT: 1' -H 'sec-ch-ua-mobile: ?0' -H 'Authorization: Basic <REDACTED>' -H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' -H 'Accept: */*' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36' -H 'X-Requested-With: XMLHttpRequest' -H 'Sec-Fetch-Site: same-origin' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Dest: empty' -H 'Accept-Language: en-US,en;q=0.9' -H 'Cookie: HttpOnly: true, Secure: true' --compressed --insecure`
curl 'https://192.168.100.1/cmconnectionstatus.html' -H 'Connection: keep-alive' -H 'sec-ch-ua: "Chromium";v="88", "Google Chrome";v="88", ";Not A Brand";v="99"' -H 'sec-ch-ua-mobile: ?0' -H 'Upgrade-Insecure-Requests: 1' -H 'DNT: 1' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' -H 'Sec-Fetch-Site: same-origin' -H 'Sec-Fetch-Mode: navigate' -H 'Sec-Fetch-User: ?1' -H 'Sec-Fetch-Dest: document' -H 'Accept-Language: en-US,en;q=0.9' -H 'Cookie: HttpOnly: true, Secure: true; credential='$cookie --compressed --insecure
This question already has an answer here:
How to make proper multipart request using Karate when file is in --form?
(1 answer)
Closed 2 years ago.
I want to run this kind of API with karate, but failed.
In this situation, the request params are both the combine of "Query String Parameters" and "From Data"; and the content-type is multipart/form-data.
Have tried many ways, always failed. I have no idea how to combine the request body and get the API request passed.
Pls help, many thanks.
Feature: get lab data list
Background:
* url xcxSaasBaseURL
# * url baseURL
Scenario: get lab data list
Given path "/nda/labprocess/list"
* params {usertoken: '#(token)'}
* multipart field LABIDS = '2fdf2349-0488-463b-93ad-886e649978e8'
When method post
Then status 200
* print "response result:", response
Here is the curl copy exported from chrome:
curl 'http://xcx.sys.saas.biosan.cn/nda/labprocess/list?usertoken=962b3afe2d354edda3fcf3f7e03ff0ea' -H 'Proxy-Connection: keep-alive' -H 'Accept: application/json, text/plain, */*' -H 'Origin: http://172.16.10.33:8090' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36' -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundarybgsYtgWxwfnBKz5f' -H 'Referer: http://172.16.10.33:8090/' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: zh-CN,zh;q=0.9' --data-binary $'------WebKitFormBoundarybgsYtgWxwfnBKz5f\r\nContent-Disposition: form-data; name="STARTDATE"\r\n\r\n\r\n------WebKitFormBoundarybgsYtgWxwfnBKz5f\r\nContent-Disposition: form-data; name="ENDDATE"\r\n\r\n\r\n------WebKitFormBoundarybgsYtgWxwfnBKz5f\r\nContent-Disposition: form-data; name="ITEMID"\r\n\r\n\r\n------WebKitFormBoundarybgsYtgWxwfnBKz5f\r\nContent-Disposition: form-data; name="QCREAGENTNUM"\r\n\r\n\r\n------WebKitFormBoundarybgsYtgWxwfnBKz5f\r\nContent-Disposition: form-data; name="PROCESSNUM"\r\n\r\n\r\n------WebKitFormBoundarybgsYtgWxwfnBKz5f\r\nContent-Disposition: form-data; name="INSTRUMENTINFO"\r\n\r\n\r\n------WebKitFormBoundarybgsYtgWxwfnBKz5f\r\nContent-Disposition: form-data; name="SRCWAY"\r\n\r\n0\r\n------WebKitFormBoundarybgsYtgWxwfnBKz5f\r\nContent-Disposition: form-data; name="PAGENUM"\r\n\r\n1\r\n------WebKitFormBoundarybgsYtgWxwfnBKz5f\r\nContent-Disposition: form-data; name="PAGESIZE"\r\n\r\n30\r\n------WebKitFormBoundarybgsYtgWxwfnBKz5f\r\nContent-Disposition: form-data; name="LABIDS"\r\n\r\n2fdf2349-0488-463b-93ad-886e649978e8\r\n------WebKitFormBoundarybgsYtgWxwfnBKz5f--\r\n' --compressed --insecure
curl 'http://xcx.sys.saas.biosan.cn/nda/labprocess/list?usertoken=962b3afe2d354edda3fcf3f7e03ff0ea' -H 'Proxy-Connection: keep-alive' -H 'Accept: application/json, text/plain, */*' -H 'Origin: http://172.16.10.33:8090' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36' -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundarybgsYtgWxwfnBKz5f' -H 'Referer: http://172.16.10.33:8090/' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: zh-CN,zh;q=0.9' --data-binary $'------WebKitFormBoundarybgsYtgWxwfnBKz5f\r\nContent-Disposition: form-data; name="STARTDATE"\r\n\r\n\r\n------WebKitFormBoundarybgsYtgWxwfnBKz5f\r\nContent-Disposition: form-data; name="ENDDATE"\r\n\r\n\r\n------WebKitFormBoundarybgsYtgWxwfnBKz5f\r\nContent-Disposition: form-data; name="ITEMID"\r\n\r\n\r\n------WebKitFormBoundarybgsYtgWxwfnBKz5f\r\nContent-Disposition: form-data; name="QCREAGENTNUM"\r\n\r\n\r\n------WebKitFormBoundarybgsYtgWxwfnBKz5f\r\nContent-Disposition: form-data; name="PROCESSNUM"\r\n\r\n\r\n------WebKitFormBoundarybgsYtgWxwfnBKz5f\r\nContent-Disposition: form-data; name="INSTRUMENTINFO"\r\n\r\n\r\n------WebKitFormBoundarybgsYtgWxwfnBKz5f\r\nContent-Disposition: form-data; name="SRCWAY"\r\n\r\n0\r\n------WebKitFormBoundarybgsYtgWxwfnBKz5f\r\nContent-Disposition: form-data; name="PAGENUM"\r\n\r\n1\r\n------WebKitFormBoundarybgsYtgWxwfnBKz5f\r\nContent-Disposition: form-data; name="PAGESIZE"\r\n\r\n30\r\n------WebKitFormBoundarybgsYtgWxwfnBKz5f\r\nContent-Disposition: form-data; name="LABIDS"\r\n\r\n2fdf2349-0488-463b-93ad-886e649978e8\r\n------WebKitFormBoundarybgsYtgWxwfnBKz5f--\r\n' --compressed --insecure
EDIT: based on the cURL you added this is my best guess as to what request you are making, note that you can form the url including query parameter manually instead of using param:
* url 'http://xcx.sys.saas.biosan.cn/nda/labprocess/list?usertoken=962b3afe2d354edda3fcf3f7e03ff0ea'
* multipart field STARTDATE = ''
* multipart field ENDDATE = ''
* multipart field ITEMID = ''
* multipart field QCREAGENTNUM = ''
* multipart field PROCESSNUM = ''
* multipart field INSTRUMENTINFO = ''
* multipart field SRCWAY = '0'
* multipart field PAGENUM = '1'
* multipart field PAGESIZE = '30'
* multipart field LABIDS = '2fdf2349-0488-463b-93ad-886e649978e8'
* method post
The request is failed when I post request an API whose header content-type is 'application/x-www-form-urlencoded; charset=UTF-8' and post body is ' param = { this is a json object} '
The curl request like this, it works.
curl 'http://localhost:7272/Acme/iEhr/PersonSample' -H 'Cookie: ACMETMP=fe35925f-a243-4be9-8e73-60c461ef9bd3; JSESSIONID=47A43F4988F232CC7B53F6CF30B954F6; SESSION=e580c2c7-bf4b-45e6-93fc-de6f79854346' -H 'Origin: http://localhost:7272' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: zh-CN,zh;q=0.9' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Accept: application/json, text/javascript, /; q=0.01' -H 'Referer: http://localhost:7272/route/sampleadd' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' --data 'param=%7B%22cityid%22%3A%222091afc3-bcd6-46d9-8033-3548ad10933b%22%2C%22areaid%22%3A%222d09f5e5-a07d-445c-9d8a-51eb436699a8%22%2C%22hosid%22%3A%220f226b63-58ad-44d7-bf23-25d0345276e1%22%2C%22deptid%22%3A%2291c176f5-63ca-4b95-87c4-9f311864ff9b%22%2C%22barcode%22%3A%221000000000%22%2C ......' --compressed
it also works with postman request but failed with Karate
Scenario: 样本登记
Given path 'iEhr/PersonSample'
And header Content-type = 'application/x-www-form-urlencoded; charset=UTF-8'
* cookies { JSESSIONID: '#(jsessionID)',SESSION: '#(sessionID)', ACMETMP: '#(acmetmpID)'}
And form fields param = {"cityid":"2091afc3-bcd6-46d9-8033-3548ad10933b","areaid":"2d09f5e5-a07d-445c-9d8a-51eb436699a8","hosid":"0f226b63-58ad-44d7-bf23-25d0345276e1","deptid":"91c176f5-63ca-4b95-87c4-9f311864ff9b","barcode":"1000000000","mothername":"manual-mother1","pregweek":"21", and so on}
When method post
Then status 200
* print response
'And form fields param = {this is a json object}'
this sentence should work but failed for us.
What is my means by karate failed ?
The response code is different compared with Karate, and it is expected result when working with postman.
Postman
the necessary param data
Karate:
18:14:09.437 request:
1 > POST http://localhost:7272/Acme/iEhr/PersonSample
1 > Accept-Encoding: gzip,deflate
1 > Connection: Keep-Alive
1 > Content-Length: 899
1 > Content-Type: application/x-www-form-urlencoded; charset=UTF-8
1 > Cookie: ACMETMP=d22c0d9a-b98b-4f6f-9e42-2f9bdffa22c8; JSESSIONID=09268B9F4CA0C15AE3FFB1A26BE424ED; SESSION=2baafdac-38d6-43d0-ac5c-d39e2b29fa48
1 > Host: localhost:7272
1 > User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_211)
cityid=2091afc3-bcd6-46d9-8033-3548ad10933b&areaid=2d09f5e5-a07d-445c-9d8a-51eb436699a8&hosid=0f226b63-58ad-44d7-bf23-25d0345276e1&deptid=91c176f5-63ca-4b95-87c4-9f311864ff9b&barcode=1000000000&mothername=manual-mother1&pregweek=21&pregday=1&midentitycard=&birthday=2018-10-01+00%3A00&collectdate=2019-05-15+14%3A38&personsex=1&personweight=4000&address=manual-testaddress1&mobile=15397006044&collectperson=&samplequality=1&borntype=1&linkman=&fidentitycard=&labitem=PHE&sampletype=1&btn=&isfee=0&personremark=&telephone=&bednumber=&labstring=&collectnumber=&freecode=&dhosid=0f226b63-58ad-44d7-bf23-25d0345276e1&reviewtype=&diagnosticstatus=¢erid=bb717701-10de-47ee-b49e-693261c6df22&nowdeptid=07eeec75-079b-4fa9-93cf-c45ddc9a87b9&operator=%E9%BB%84%E5%86%88%E5%B8%82%E5%A6%87%E5%B9%BC%E4%BF%9D%E5%81%A5%E9%99%A2&labitems=PHE&pagecode=sampleadd&modifydetail=%E6%A0%B7%E6%9C%AC%E5%BD%95%E5%85%A5
18:14:09.557 response time in milliseconds: 120.12
1 < 200
1 < Accept-Charset: big5, big5-hkscs, cesu-8, euc-jp, euc-kr, gb18030, gb2312, gbk, ibm-thai ...... and so on
1 < Content-Length: 52
1 < Content-Type: text/plain;charset=UTF-8
1 < Date: Wed, 15 May 2019 10:14:09 GMT
1 < X-Application-Context: Acme.jc.test:dev:7272
[{"code":-90018,"result":"(错误-90018)失败!"}]
Can you try this,
Scenario: 样本登记
Given path 'iEhr/PersonSample'
* cookies { JSESSIONID: '#(jsessionID)',SESSION: '#(sessionID)', ACMETMP: '#(acmetmpID)'}
And def ffParams = {"param" : {"cityid":"2091afc3-bcd6-46d9-8033-3548ad10933b","areaid":"2d09f5e5-a07d-445c-9d8a-51eb436699a8","hosid":"0f226b63-58ad-44d7-bf23-25d0345276e1","deptid":"91c176f5-63ca-4b95-87c4-9f311864ff9b","barcode":"1000000000","mothername":"manual-mother1","pregweek":"21"}}
And form fields ffParams
When method post
Then status 200
* print response
Form fields are by default url-encoded only no need to explicitly mention it in header
And form field param = {"cityid":"2091afc3-bcd6-46d9-8033-3548ad10933b","areaid":"2d09f5e5-a07d-445c-9d8a-51eb436699a8","hosid":"0f226b63-58ad-44d7-bf23-25d0345276e1","deptid":"91c176f5-63ca-4b95-87c4-9f311864ff9b","barcode":"1000000000","mothername":"manual-mother1","pregweek":"21","pregday":"1","midentitycard":"","birthday":"2018-10-01 00:00" ...... and so on }
I changed to this, it works now.
I am misled by the keyword 'param' in karate and the keyword 'param' used by our product code.