后请求正文不解析变量



我有一个使用rest-assured的简单测试,如下所示。案例1:如果我像下面这样传递json字符串,它工作得很好。

@Test
public void dummyTest throws Exception() {
String newUserEmail = "postOrder" + UUID.randomUUID() + "@gmail.com";
String json = "{n" +
"    "name": "Marisa",n" +
"    "birthday": "1997-10-06",n" +
"    "title": "Dr.",n" +
"    "email": "postOrder26@gmail.com",n" +
"  },n" 
given()
.baseUri("my_request_url")
.header("Content-Type", "application/json")
.body(json)
.when()
.post()
.then()
.log().all();
}

上面返回200响应。


但是如果我像下面这样写测试,将email作为变量传递,返回500

@Test
public void dummyTest throws Exception() {
String newUserEmail = "postOrder" + UUID.randomUUID() + "@gmail.com";
String json = "{n" +
"    "name": "Marisa",n" +
"    "birthday": "1997-10-06",n" +
"    "title": "Dr.",n" +
"    "email": ""+newUserEmail+"",n" +
"  },n" 
given()
.baseUri("my_request_url")
.header("Content-Type", "application/json")
.body(json)
.when()
.post()
.then()
.log().all();
}

我得到500个错误响应

HTTP/1.1 500 Internal Server Error
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Date: Mon, 16 Aug 2021 17:05:36 GMT
Server: Apache
Cache-Control: no-cache, private
X-Cache: Error from cloudfront
Via: 1.1 871dedfc10f4428aa2412b6f788b791a.cloudfront.net (CloudFront)
X-Amz-Cf-Pop: ZRH50-C1
X-Amz-Cf-Id: xGkO8cJGV0Pq7wAx71YyglWzQNdZzooohqZLZBHkC54iZgiNhGmpEA==
<html>
<head>
<meta name="robots" content="noindex,nofollow"/>
<style>
/* Copyright (c) 2010, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: https://yuilibrary.com/license/ */
html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}li{list-style:none;}caption,th{text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym{border:0;font-variant:normal;}sup{vertical-align:text-top;}sub{vertical-align:text-bottom;}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;}input,textarea,select{*font-size:100%;}legend{color:#000;}
html { background: #eee; padding: 10px }
img { border: 0; }
#sf-resetcontent { width:970px; margin:0 auto; }
body { background-color: #fff; color: #222; font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; margin: 0; }
.container { margin: 30px; max-width: 600px; }
h1 { color: #dc3545; font-size: 24px; }
</style>
</head>
<body>

谁能告诉我,如何解决这500个错误

你的问题可能在这里得到回答:Grails -将UUID呈现为JSON

UUID数据类型不是字符串,而是位图数字,因此在连接之前需要将其转换为字符串。. tostring()函数应该修复第二个块。我不确定"+"的具体内容。操作符,但我相信类型转换与c。

最新更新