gpt4 book ai didi

json - 如何在 Stringbody 中传递 json 字符串以及 Ga特林中的动态值?

转载 作者:行者123 更新时间:2023-12-04 21:48:01 25 4
gpt4 key购买 nike

我必须在我的加特林请求的 StringBody 中传递这个字符串

{"definitionId":4891544, "stringVariables" : {"Copy 1-json-metadata-instance":" {\r\n \"external-resource\": {\r\n \"id\": 4881561,\r\n \"name\": \"Training Outbound-File\",\r\n \"type\": \"resource\"\r\n },\r\n \"asset-context\": {\r\n \"value\": \".\",\r\n \"isExpression\": false\r\n },\r\n \"vfs-location\": {\r\n \"protocol\": \"FILE\",\r\n \"port\": 0,\r\n \"path\": \"/fx/fx-enterprise/storage/media/Training Outbound-FILE\"\r\n }", "Copy 2-json-metadata-instance":" {\r\n \"external-resource\": {\r\n \"id\": 48218841,\r\n \"name\": \"Training Outbound-File\",\r\n \"type\": \"resource\"\r\n },\r\n \"asset-context\": {\r\n \"value\": \".\",\r\n \"isExpression\": false\r\n },\r\n \"vfs-location\": {\r\n \"protocol\": \"FTP\",\r\n \"hostname\": \"ntvt.upload.llnw.net\",\r\n \"port\": 0,\r\n \"path\": \"/poc/V5Dev/R1\",\r\n \"username\": \"ntvt-ht-nt-staging\",\r\n \"password\": \"jpc6t8\"\r\n }"} }}}

这是我的 Scala 脚本

// Dynamic Json values  
val filePath = System.getProperty("filePath", "/fx/fx-enterprise/storage/media/Training Outbound-FILE")
val ftpHostname = System.getProperty("ftpHostname", "ntvt.upload.llnw.net")
val ftpUsername = System.getProperty("ftpUsername", "ntvt-ht-nt-staging")
val ftpPassword = System.getProperty("ftpPassword", "jpc6t8")
val ftpPath = System.getProperty("ftpPath", "/poc/V5Dev/R1")
val UUID = System.getProperty("UUID", "b71awerv-4946-4bwe-8eqa-2412fgh98002")
val definitionId = System.getProperty("definitionId", "48924212")

val scn = scenario("Launch")
.exec(http("Wf")
.post("""/api/workflows""")
.headers(headers_0)
// Modification-1
.body(StringBody(s"""{"definitionId":"${definitionId}", "stringVariables" : { "Copy 1-json-metadata-instance":" {\r\n \"external-resource\": {\r\n \"id\": 488841,\r\n \"name\": \"Training Outbound-File\",\r\n \"type\": \"resource\"\r\n },\r\n \"asset-context\": {\r\n \"value\": \".\",\r\n \"isExpression\": false\r\n },\r\n \"vfs-location\": {\r\n \"protocol\": \"FILE\",\r\n \"port\": 0,\r\n \"path\": \"${filePath}\"\r\n }", "Copy 2-json-metadata-instance":" {\r\n \"external-resource\": {\r\n \"id\": 488841,\r\n \"name\": \"Training Outbound-File\",\r\n \"type\": \"resource\"\r\n },\r\n \"asset-context\": {\r\n \"value\": \".\",\r\n \"isExpression\": false\r\n },\r\n \"vfs-location\": {\r\n \"protocol\": \"FTP\",\r\n \"hostname\": \"${ftpHostname}\",\r\n \"port\": 0,\r\n \"path\": \"${ftpPath}\",\r\n \"username\": \"${ftpUsername}\",\r\n \"password\": \"${ftpPassword}\"\r\n }"} } }}""")).asJSON)

//Modification-2
// .body(StringBody(s"""{"definitionId":"$definitionId", "stringVariables" : { "Copy 1-json-metadata-instance":" {"external-resource": {"id": 488841,"name": "Training Outbound-File", "type": "resource"},"asset-context": {"value": ".","isExpression": false},"vfs-location": {"protocol": "FILE","port": 0,"path": "$filePath"}", "Copy 2-json-metadata-instance":" {"external-resource": {"id": 488841,"name": "Training Outbound-File","type": "resource"},"asset-context": {"value": ".","isExpression": false},"vfs-location": {"protocol": "FTP","hostname": "$ftpHostname","port": 0,"path": "$ftpPath","username": "$ftpUsername","password": "$ftpPassword"}"} } }}""")))

setUp(scn.inject(atOnceUsers(userCount))).protocols(httpProtocol)

如果我传递原始字符串,因为它没有动态值,它就会起作用)抛出以下错误:

====修改后的输出-1====

compositeByteData={"definitionId":"4891544", "stringVariables" : { "Copy 1-json-metadata-instance":"
{
"external-resource": {
"id": 488841,
"name": "Training Outbound-File",
"type": "resource"
},
"asset-context": {
"value": ".",
"isExpression": false
},
"vfs-location": {
"protocol": "FILE",
"port": 0,
"path": "/fx/fx-enterprise/storage/media/Training Outbound-FILE"
}", "Copy 2-json-metadata-instance":" {
"external-resource": {
"id": 488841,
"name": "Training Outbound-File",
"type": "resource"
},
"asset-context": {
"value": ".",
"isExpression": false
},
"vfs-location": {
"protocol": "FTP",
"hostname": "ntvt.upload.llnw.net",
"port": 0,
"path": "/poc/V5Dev/R1",
"username": "ntvt-ht-nt-staging",
"password": "jpc6t8"
}"} } }}
realm=Realm{principal='masteruser', password='masteruser', scheme=BASIC, realmName='null', nonce='n
ull', algorithm='null', response='null', qop='null', nc='00000001', cnonce='null', uri='null', meth
odName='GET', useAbsoluteURI='false', omitQuery='false'}
=========================
HTTP response:
status=
500 Internal Server Error
headers=
Content-Type: [application/json]
Date: [Tue, 20 Dec 2016 10:41:29 GMT]
Server: [Apache-Coyote/1.1]
Content-Length: [69]
Connection: [keep-alive]

body=
{
"errors" : {
"error" : "Error while processing request"
}
}

====修改后的输出-2====

body=
{
"errors" : {
"error" : "Unexpected character ('e' (code 101)): was expecting comma to separate OBJECT entries\n at [Source: org.apache.catalina.connector.CoyoteInputStream@201d449c; line: 1, column: 86]"
}
}

最佳答案

我格式化了 JSON 字符串主体,发现 JSON 对象开始声明的地方有引号。看截图。我不确定您的 JSON 是否有效 enter image description here

关于json - 如何在 Stringbody 中传递 json 字符串以及 Ga特林中的动态值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41257358/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com