我正试图对graphql端点进行简单的rest调用,但从服务器获得400
错误。我在这方面已经有一段时间了
有效载荷
query = "{n" +
" lookup(dob: "01/01", preSsn : { ssn: "{actualvalue}"})n" +
" {n" +
" items {n" +
" individualCrdNumbern" +
" firstNamen" +
" middleNamen" +
" lastNamen" +
" suffixNamen" +
" }n" +
" }n" +
"}";
错误信息:{"statusCode":400,"statusDescription":"Bad Request","message":"","messageDetails":[]}
代码:
HttpClient client = getHttpsClient();
HttpPost httpPost = new HttpPost(URL);
StringEntity input = new StringEntity(query, ContentType.APPLICATION_JSON);
httpPost.setEntity(input);
final String plainCred = "userName"+":"+"password";
final String base64Creds = Base64.getEncoder().encodeToString(plainCred.getBytes());
httpPost.addHeader("Authorization", "Basic " + base64Creds);
httpPost.addHeader("Content-Type", "application/json");
httpPost.addHeader("Accept", "application/json");
httpPost.addHeader("Cache-Control", "no-cache");
HttpResponse response = client.execute(httpPost);
查询需要封装在分配给query
元素的对象中。该对象还可以包含用于值绑定的variables
元素:
{
"query": "...",
"operationName": "...",
"variables": { "myVariable": "someValue", ... }
}
参见使用POST的HTTP上的GraphQL规范。
试
String query =
"{" +
""query" : "query {"+
"lookup(dob: "01/01", preSsn : { ssn: "{actualvalue}"})" +
"{items{individualCrdNumber firstName middleName lastName suffixName}}" +
"}" +
"}";