【发布时间】:2018-12-13 09:45:31
【问题描述】:
我有一个在正文中包含 graphQL 查询的请求。
当我发布它时,它会返回一个带有Content-Type →text/html; charset=utf-8 和其他一些常用标题的响应。 txt/html 响应通常包括两件事:
- ColDefs 作为第一行
- 第二行的元数据
现在我需要验证 ColDefs 是否始终出现在第一行。第二行包含元数据。
如何确保响应的第一行始终包含 colDefs 而第二行包含元数据信息?
回应:
{
"colDefs": [{
"entityAttributeId": "abc",
"headerName": "xyz",
"field": "2",
"entityPath": "",
"entityId": "mna"
}, {
"entityAttributeId": "abc",
"headerName": "abc",
"field": "3",
"entityPath": "abc",
"entityId": "abc"
}
]
} {
"1": "1000",
"2": "abc",
"3": "abc",
"4": 12,
"5": "6457.T",
"6": "123",
"7": "abc"
} {
"1": "123",
"2": "abc",
"3": "abc",
"4": 123,
"5": "123",
"6": "",
"7": "abc"
}
当我尝试打印空手道响应时,它没有打印第二行(元数据)内容,它只是打印 colDefs。
空手道反应:
{
"colDefs": [{
"entityAttributeId": "abc",
"headerName": "xyz",
"field": "2",
"entityPath": "",
"entityId": "mna"
}, {
"entityAttributeId": "abc",
"headerName": "abc",
"field": "3",
"entityPath": "abc",
"entityId": "abc"
}
复制步骤:
网址:一些网址
Headers: Content-Type = 'application/json'
(在空手道功能中明确发送),
请求正文
{
"query": "query($someid: [String]) {some(someid:$someid) {someid someNm someVariable {someVariable someVariableid otherVariable{ otherVariable1 { variable CUSIP issuer { someVariable2 }}}}}}",
"variables": {
"someid": ["1090"]
},
"includeMetadata": false
}
Response Header: Connection →keep-alive
Content-Length →86488
Content-Type →text/html; charset=utf-8
响应正文:
{
"colDefs": [{
"entityAttributeId": "abc",
"headerName": "xyz",
"field": "2",
"entityPath": "",
"entityId": "mna"
}, {
"entityAttributeId": "abc",
"headerName": "abc",
"field": "3",
"entityPath": "abc",
"entityId": "abc"
}
]
} {
"1": "1000",
"2": "abc",
"3": "abc",
"4": 12,
"5": "6457.T",
"6": "123",
"7": "abc"
} {
"1": "123",
"2": "abc",
"3": "abc",
"4": 123,
"5": "123",
"6": "",
"7": "abc"
}
空手道反应:
{
"colDefs": [{
"entityAttributeId": "abc",
"headerName": "xyz",
"field": "2",
"entityPath": "",
"entityId": "mna"
}, {
"entityAttributeId": "abc",
"headerName": "abc",
"field": "3",
"entityPath": "abc",
"entityId": "abc"
}
【问题讨论】:
-
然后匹配 response.colDefs == "coldef"。这行得通。但是元数据验证呢?如何到达那里?打印响应仅显示 colDefs。
-
@PeterThomas 如何打印空手道的整个文本/html 响应?看起来它只保存了部分响应,这是一种 json。
-
完成。我们现在可以从这里开始吗?
-
我很困惑?响应是 HTML 吗?您可以粘贴响应的确切文本形式吗?空手道不会神奇地将 html 转换为 json。
-
用其他细节更新了相关细节。