Используя GitHub GraphQL API программно, получаю неверный запрос с RestTemplate.execute, но на Почтальоне работает нормально - PullRequest
2 голосов
/ 07 января 2020

Я пытаюсь использовать API GitHub v4 с использованием GraphQL из приложения Spring Boot (а именно, мое приложение - это сервер, который пытается использовать API для службы в рамках разрешения GET запрос на одном из контроллеров приложения).

Я попытался выполнить следующий тестовый POST-запрос к Postman, получая данные, которые я ожидал успешно:

POST /graphql HTTP/1.1
Host: api.github.com
Content-Type: application/json
Authorization: Bearer [MY PERSONAL GITHUB TOKEN]
User-Agent: PostmanRuntime/7.20.1
Accept: */*
Cache-Control: no-cache
Postman-Token: 55f54f00-83f6-4acb-a6f8-4a3bde9147e7,abb6f600-8b79-4697-bd31-e04836386a24
Host: api.github.com
Accept-Encoding: gzip, deflate
Content-Length: 264
Connection: keep-alive
cache-control: no-cache

query{repository(owner:"ccjmk", name:"super-happiness"){object(expression:"master"){... on Commit{history{totalCount}}}}}

Ответ:

{"data":{"repository":{"object":{"history":{"totalCount":19}}}}}

(я не вижу заметных заголовков, но я мог бы добавить все, что могло бы быть полезным)

Затем, на конце Java, я попробовал это в сервисе: (Я также пытался нажать API v3 успешно, добавление метода, используемого в службе тоже для справки)

    @Override
    public String fetchCommitsv3(String ownerUsername, String repository) {

        final String uri = String.format("https://api.github.com/repos/%s/%s/commits", ownerUsername, repository);

        RestTemplate restTemplate = new RestTemplate();
        String result = restTemplate.getForObject(uri, String.class);
        return result;
    }

    @Override
    public ResponseEntity<String> fetchCommitsv4(String ownerUsername, String repository) {

        final String uri = String.format("https://api.github.com/graphql");
        String query = "query{repository(owner:\""+ownerUsername+"\", name:\""+repository+"\"){object(expression:\"master\"){... on Commit{history{totalCount}}}}}";

        String gitHubToken = [MY GITHUB TOKEN];

        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setRequestFactory(new HttpComponentsAsyncClientHttpRequestFactory());
        HttpHeaders headers = new HttpHeaders();
        //headers.add("Authorization", "Bearer "+gitHubToken);
        headers.set("Authorization","Bearer "+gitHubToken);
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<String> entity = new HttpEntity<>(query, headers);

        ResponseEntity<String> result = restTemplate.exchange(uri, HttpMethod.POST, entity, String.class);
        return result;
    }

Это вызывает ответ 400 Bad Request, в конце полный пост. Для меня оба запроса выглядят одинаково, но они, безусловно, разные, только я не могу точно определить, где! Любая помощь будет высоко ценится, потому что я уверен,


SpringBoot Log:

2020-01-07 16:48:24.419 DEBUG 21236 --- [nio-8088-exec-1] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/tdd/insights/github/v4/commits/ccjmk/super-happiness]
2020-01-07 16:48:24.432 DEBUG 21236 --- [nio-8088-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /tdd/insights/github/v4/commits/ccjmk/super-happiness
2020-01-07 16:48:24.450 DEBUG 21236 --- [nio-8088-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.http.ResponseEntity com.penguin.formula.tdd.web.controller.InsightsController.commitsv4(java.lang.String,java.lang.String) throws java.lang.Exception]
2020-01-07 16:48:24.451 DEBUG 21236 --- [nio-8088-exec-1] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/tdd/insights/github/v4/commits/ccjmk/super-happiness] is: -1
2020-01-07 16:51:35.166 DEBUG 21236 --- [nio-8088-exec-1] o.s.web.client.RestTemplate              : Created POST request for "https://api.github.com/graphql"
2020-01-07 16:51:35.169 DEBUG 21236 --- [nio-8088-exec-1] o.s.web.client.RestTemplate              : Setting request Accept header to [text/plain, application/json, application/*+json, */*]
2020-01-07 16:51:35.182 DEBUG 21236 --- [nio-8088-exec-1] o.s.web.client.RestTemplate              : Writing [query{repository(owner:"ccjmk", name:"super-happiness"){object(expression:"master"){... on Commit{history{totalCount}}}}}] as "application/json" using [org.springframework.http.converter.StringHttpMessageConverter@7dcd6967]
2020-01-07 16:51:35.404 DEBUG 21236 --- [nio-8088-exec-1] o.a.h.client.protocol.RequestAddCookies  : CookieSpec selected: default
2020-01-07 16:51:35.607 DEBUG 21236 --- [nio-8088-exec-1] o.a.h.client.protocol.RequestAuthCache   : Auth cache not set in the context
2020-01-07 16:51:35.644 DEBUG 21236 --- [nio-8088-exec-1] h.i.c.PoolingHttpClientConnectionManager : Connection request: [route: {s}->https://api.github.com:443][total kept alive: 0; route allocated: 0 of 5; total allocated: 0 of 10]
2020-01-07 16:51:35.861 DEBUG 21236 --- [nio-8088-exec-1] h.i.c.PoolingHttpClientConnectionManager : Connection leased: [id: 0][route: {s}->https://api.github.com:443][total kept alive: 0; route allocated: 1 of 5; total allocated: 1 of 10]
2020-01-07 16:51:35.889 DEBUG 21236 --- [nio-8088-exec-1] o.a.http.impl.execchain.MainClientExec   : Opening connection {s}->https://api.github.com:443
2020-01-07 16:51:35.928 DEBUG 21236 --- [nio-8088-exec-1] .i.c.DefaultHttpClientConnectionOperator : Connecting to api.github.com/140.82.118.5:443
2020-01-07 16:51:35.930 DEBUG 21236 --- [nio-8088-exec-1] o.a.h.c.ssl.SSLConnectionSocketFactory   : Connecting socket to api.github.com/140.82.118.5:443 with timeout 0
2020-01-07 16:51:35.983 DEBUG 21236 --- [nio-8088-exec-1] o.a.h.c.ssl.SSLConnectionSocketFactory   : Enabled protocols: [TLSv1, TLSv1.1, TLSv1.2]
2020-01-07 16:51:35.988 DEBUG 21236 --- [nio-8088-exec-1] o.a.h.c.ssl.SSLConnectionSocketFactory   : Enabled cipher suites:[TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, TLS_DHE_DSS_WITH_AES_256_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_DSS_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_DSS_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
2020-01-07 16:51:35.993 DEBUG 21236 --- [nio-8088-exec-1] o.a.h.c.ssl.SSLConnectionSocketFactory   : Starting handshake
2020-01-07 16:51:36.648 DEBUG 21236 --- [nio-8088-exec-1] o.a.h.c.ssl.SSLConnectionSocketFactory   : Secure session established
2020-01-07 16:51:36.651 DEBUG 21236 --- [nio-8088-exec-1] o.a.h.c.ssl.SSLConnectionSocketFactory   :  negotiated protocol: TLSv1.2
2020-01-07 16:51:36.654 DEBUG 21236 --- [nio-8088-exec-1] o.a.h.c.ssl.SSLConnectionSocketFactory   :  negotiated cipher suite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
2020-01-07 16:51:36.658 DEBUG 21236 --- [nio-8088-exec-1] o.a.h.c.ssl.SSLConnectionSocketFactory   :  peer principal: CN=*.github.com, O="GitHub, Inc.", L=San Francisco, ST=California, C=US
2020-01-07 16:51:36.661 DEBUG 21236 --- [nio-8088-exec-1] o.a.h.c.ssl.SSLConnectionSocketFactory   :  peer alternative names: [*.github.com, github.com]
2020-01-07 16:51:36.665 DEBUG 21236 --- [nio-8088-exec-1] o.a.h.c.ssl.SSLConnectionSocketFactory   :  issuer principal: CN=DigiCert SHA2 High Assurance Server CA, OU=www.digicert.com, O=DigiCert Inc, C=US
2020-01-07 16:51:36.700 DEBUG 21236 --- [nio-8088-exec-1] .i.c.DefaultHttpClientConnectionOperator : Connection established 192.168.1.98:48784<->140.82.118.5:443
2020-01-07 16:51:36.702 DEBUG 21236 --- [nio-8088-exec-1] o.a.http.impl.execchain.MainClientExec   : Executing request POST /graphql HTTP/1.1
2020-01-07 16:51:36.705 DEBUG 21236 --- [nio-8088-exec-1] o.a.http.impl.execchain.MainClientExec   : Proxy auth state: UNCHALLENGED
2020-01-07 16:51:36.743 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 >> POST /graphql HTTP/1.1
2020-01-07 16:51:36.745 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 >> Accept: text/plain, application/json, application/*+json, */*
2020-01-07 16:51:36.747 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 >> Authorization: Bearer {{MY PERSONAL TOKEN}}
2020-01-07 16:51:36.748 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 >> Content-Type: application/json
2020-01-07 16:51:36.752 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 >> Accept-Charset: big5, big5-hkscs, cesu-8, euc-jp, euc-kr, gb18030, gb2312, gbk, ibm-thai, ibm00858, ibm01140, ibm01141, ibm01142, ibm01143, ibm01144, ibm01145, ibm01146, ibm01147, ibm01148, ibm01149, ibm037, ibm1026, ibm1047, ibm273, ibm277, ibm278, ibm280, ibm284, ibm285, ibm290, ibm297, ibm420, ibm424, ibm437, ibm500, ibm775, ibm850, ibm852, ibm855, ibm857, ibm860, ibm861, ibm862, ibm863, ibm864, ibm865, ibm866, ibm868, ibm869, ibm870, ibm871, ibm918, iso-2022-cn, iso-2022-jp, iso-2022-jp-2, iso-2022-kr, iso-8859-1, iso-8859-13, iso-8859-15, iso-8859-2, iso-8859-3, iso-8859-4, iso-8859-5, iso-8859-6, iso-8859-7, iso-8859-8, iso-8859-9, jis_x0201, jis_x0212-1990, koi8-r, koi8-u, shift_jis, tis-620, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-32be, utf-32le, utf-8, windows-1250, windows-1251, windows-1252, windows-1253, windows-1254, windows-1255, windows-1256, windows-1257, windows-1258, windows-31j, x-big5-hkscs-2001, x-big5-solaris, x-compound_text, x-euc-jp-linux, x-euc-tw, x-eucjp-open, x-ibm1006, x-ibm1025, x-ibm1046, x-ibm1097, x-ibm1098, x-ibm1112, x-ibm1122, x-ibm1123, x-ibm1124, x-ibm1166, x-ibm1364, x-ibm1381, x-ibm1383, x-ibm300, x-ibm33722, x-ibm737, x-ibm833, x-ibm834, x-ibm856, x-ibm874, x-ibm875, x-ibm921, x-ibm922, x-ibm930, x-ibm933, x-ibm935, x-ibm937, x-ibm939, x-ibm942, x-ibm942c, x-ibm943, x-ibm943c, x-ibm948, x-ibm949, x-ibm949c, x-ibm950, x-ibm964, x-ibm970, x-iscii91, x-iso-2022-cn-cns, x-iso-2022-cn-gb, x-iso-8859-11, x-jis0208, x-jisautodetect, x-johab, x-macarabic, x-maccentraleurope, x-maccroatian, x-maccyrillic, x-macdingbat, x-macgreek, x-machebrew, x-maciceland, x-macroman, x-macromania, x-macsymbol, x-macthai, x-macturkish, x-macukraine, x-ms932_0213, x-ms950-hkscs, x-ms950-hkscs-xp, x-mswin-936, x-pck, x-sjis_0213, x-utf-16le-bom, x-utf-32be-bom, x-utf-32le-bom, x-windows-50220, x-windows-50221, x-windows-874, x-windows-949, x-windows-950, x-windows-iso2022jp
2020-01-07 16:51:36.755 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 >> Content-Length: 121
2020-01-07 16:51:36.757 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 >> Host: api.github.com
2020-01-07 16:51:36.759 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 >> Connection: Keep-Alive
2020-01-07 16:51:36.760 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_232)
2020-01-07 16:51:36.762 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 >> Accept-Encoding: gzip,deflate
2020-01-07 16:51:36.770 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 >> "POST /graphql HTTP/1.1[\r][\n]"
2020-01-07 16:51:36.773 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 >> "Accept: text/plain, application/json, application/*+json, */*[\r][\n]"
2020-01-07 16:51:36.774 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 >> "Authorization: Bearer {{MY PERSONAL TOKEN}}[\r][\n]"
2020-01-07 16:51:36.776 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 >> "Content-Type: application/json[\r][\n]"
2020-01-07 16:51:36.781 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 >> "Accept-Charset: big5, big5-hkscs, cesu-8, euc-jp, euc-kr, gb18030, gb2312, gbk, ibm-thai, ibm00858, ibm01140, ibm01141, ibm01142, ibm01143, ibm01144, ibm01145, ibm01146, ibm01147, ibm01148, ibm01149, ibm037, ibm1026, ibm1047, ibm273, ibm277, ibm278, ibm280, ibm284, ibm285, ibm290, ibm297, ibm420, ibm424, ibm437, ibm500, ibm775, ibm850, ibm852, ibm855, ibm857, ibm860, ibm861, ibm862, ibm863, ibm864, ibm865, ibm866, ibm868, ibm869, ibm870, ibm871, ibm918, iso-2022-cn, iso-2022-jp, iso-2022-jp-2, iso-2022-kr, iso-8859-1, iso-8859-13, iso-8859-15, iso-8859-2, iso-8859-3, iso-8859-4, iso-8859-5, iso-8859-6, iso-8859-7, iso-8859-8, iso-8859-9, jis_x0201, jis_x0212-1990, koi8-r, koi8-u, shift_jis, tis-620, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-32be, utf-32le, utf-8, windows-1250, windows-1251, windows-1252, windows-1253, windows-1254, windows-1255, windows-1256, windows-1257, windows-1258, windows-31j, x-big5-hkscs-2001, x-big5-solaris, x-compound_text, x-euc-jp-linux, x-euc-tw, x-eucjp-open, x-ibm1006, x-ibm1025, x-ibm1046, x-ibm1097, x-ibm1098, x-ibm1112, x-ibm1122, x-ibm1123, x-ibm1124, x-ibm1166, x-ibm1364, x-ibm1381, x-ibm1383, x-ibm300, x-ibm33722, x-ibm737, x-ibm833, x-ibm834, x-ibm856, x-ibm874, x-ibm875, x-ibm921, x-ibm922, x-ibm930, x-ibm933, x-ibm935, x-ibm937, x-ibm939, x-ibm942, x-ibm942c, x-ibm943, x-ibm943c, x-ibm948, x-ibm949, x-ibm949c, x-ibm950, x-ibm964, x-ibm970, x-iscii91, x-iso-2022-cn-cns, x-iso-2022-cn-gb, x-iso-8859-11, x-jis0208, x-jisautodetect, x-johab, x-macarabic, x-maccentraleurope, x-maccroatian, x-maccyrillic, x-macdingbat, x-macgreek, x-machebrew, x-maciceland, x-macroman, x-macromania, x-macsymbol, x-macthai, x-macturkish, x-macukraine, x-ms932_0213, x-ms950-hkscs, x-ms950-hkscs-xp, x-mswin-936, x-pck, x-sjis_0213, x-utf-16le-bom, x-utf-32be-bom, x-utf-32le-bom, x-windows-50220, x-windows-50221, x-windows-874, x-windows-949, x-windows-950, x-windows-iso2022jp[\r][\n]"
2020-01-07 16:51:36.783 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 >> "Content-Length: 121[\r][\n]"
2020-01-07 16:51:36.785 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 >> "Host: api.github.com[\r][\n]"
2020-01-07 16:51:36.787 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
2020-01-07 16:51:36.789 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_232)[\r][\n]"
2020-01-07 16:51:36.791 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
2020-01-07 16:51:36.793 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 >> "[\r][\n]"
2020-01-07 16:51:36.795 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 >> "query{repository(owner:"ccjmk", name:"super-happiness"){object(expression:"master"){... on Commit{history{totalCount}}}}}"
2020-01-07 16:51:37.070 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "HTTP/1.1 400 Bad Request[\r][\n]"
2020-01-07 16:51:37.077 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "Date: Tue, 07 Jan 2020 16:51:36 GMT[\r][\n]"
2020-01-07 16:51:37.083 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "Content-Type: application/json; charset=utf-8[\r][\n]"
2020-01-07 16:51:37.087 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "Content-Length: 89[\r][\n]"
2020-01-07 16:51:37.091 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "Server: GitHub.com[\r][\n]"
2020-01-07 16:51:37.094 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "Status: 400 Bad Request[\r][\n]"
2020-01-07 16:51:37.097 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "Cache-Control: no-cache[\r][\n]"
2020-01-07 16:51:37.099 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "X-OAuth-Scopes: read:enterprise, read:org, read:packages, read:repo_hook, read:user, repo[\r][\n]"
2020-01-07 16:51:37.101 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "X-Accepted-OAuth-Scopes: repo[\r][\n]"
2020-01-07 16:51:37.103 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "X-GitHub-Media-Type: unknown, github.v4[\r][\n]"
2020-01-07 16:51:37.105 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "X-RateLimit-Limit: 5000[\r][\n]"
2020-01-07 16:51:37.107 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "X-RateLimit-Remaining: 5000[\r][\n]"
2020-01-07 16:51:37.109 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "X-RateLimit-Reset: 1578419496[\r][\n]"
2020-01-07 16:51:37.112 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type[\r][\n]"
2020-01-07 16:51:37.114 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "Access-Control-Allow-Origin: *[\r][\n]"
2020-01-07 16:51:37.116 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "Strict-Transport-Security: max-age=31536000; includeSubdomains; preload[\r][\n]"
2020-01-07 16:51:37.118 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "X-Frame-Options: deny[\r][\n]"
2020-01-07 16:51:37.119 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "X-Content-Type-Options: nosniff[\r][\n]"
2020-01-07 16:51:37.121 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "X-XSS-Protection: 1; mode=block[\r][\n]"
2020-01-07 16:51:37.123 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin[\r][\n]"
2020-01-07 16:51:37.125 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "Content-Security-Policy: default-src 'none'[\r][\n]"
2020-01-07 16:51:37.127 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "X-GitHub-Request-Id: BE90:B6DD:27E5493C:2F86CC08:5E14B718[\r][\n]"
2020-01-07 16:51:37.129 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "[\r][\n]"
2020-01-07 16:51:37.131 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.wire                     : http-outgoing-0 << "{"message":"Problems parsing JSON","documentation_url":"https://developer.github.com/v4"}"
2020-01-07 16:51:37.175 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << HTTP/1.1 400 Bad Request
2020-01-07 16:51:37.177 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << Date: Tue, 07 Jan 2020 16:51:36 GMT
2020-01-07 16:51:37.178 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << Content-Type: application/json; charset=utf-8
2020-01-07 16:51:37.180 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << Content-Length: 89
2020-01-07 16:51:37.182 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << Server: GitHub.com
2020-01-07 16:51:37.184 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << Status: 400 Bad Request
2020-01-07 16:51:37.185 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << Cache-Control: no-cache
2020-01-07 16:51:37.187 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << X-OAuth-Scopes: read:enterprise, read:org, read:packages, read:repo_hook, read:user, repo
2020-01-07 16:51:37.189 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << X-Accepted-OAuth-Scopes: repo
2020-01-07 16:51:37.191 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << X-GitHub-Media-Type: unknown, github.v4
2020-01-07 16:51:37.192 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << X-RateLimit-Limit: 5000
2020-01-07 16:51:37.194 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << X-RateLimit-Remaining: 5000
2020-01-07 16:51:37.195 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << X-RateLimit-Reset: 1578419496
2020-01-07 16:51:37.197 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type
2020-01-07 16:51:37.199 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << Access-Control-Allow-Origin: *
2020-01-07 16:51:37.200 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
2020-01-07 16:51:37.202 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << X-Frame-Options: deny
2020-01-07 16:51:37.204 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << X-Content-Type-Options: nosniff
2020-01-07 16:51:37.206 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << X-XSS-Protection: 1; mode=block
2020-01-07 16:51:37.207 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
2020-01-07 16:51:37.209 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << Content-Security-Policy: default-src 'none'
2020-01-07 16:51:37.210 DEBUG 21236 --- [nio-8088-exec-1] org.apache.http.headers                  : http-outgoing-0 << X-GitHub-Request-Id: BE90:B6DD:27E5493C:2F86CC08:5E14B718
2020-01-07 16:51:37.288 DEBUG 21236 --- [nio-8088-exec-1] o.a.http.impl.execchain.MainClientExec   : Connection can be kept alive indefinitely
2020-01-07 16:51:37.336 DEBUG 21236 --- [nio-8088-exec-1] o.s.web.client.RestTemplate              : POST request for "https://api.github.com/graphql" resulted in 400 (Bad Request); invoking error handler
2020-01-07 16:51:37.375 DEBUG 21236 --- [nio-8088-exec-1] h.i.c.PoolingHttpClientConnectionManager : Connection [id: 0][route: {s}->https://api.github.com:443] can be kept alive indefinitely
2020-01-07 16:51:37.377 DEBUG 21236 --- [nio-8088-exec-1] h.i.c.DefaultManagedHttpClientConnection : http-outgoing-0: set socket timeout to 0
2020-01-07 16:51:37.380 DEBUG 21236 --- [nio-8088-exec-1] h.i.c.PoolingHttpClientConnectionManager : Connection released: [id: 0][route: {s}->https://api.github.com:443][total kept alive: 1; route allocated: 1 of 5; total allocated: 1 of 10]

1 Ответ

1 голос
/ 08 января 2020

Итак, благодаря Виму Деблаве, который намекнул, что Content-Lenghts отключен по запросу JSON, я заметил следующее:

Я использовал режим тела GraphQL на Postman, который (без моего ведома, Вы должны прочитать документацию, ребята!) На самом деле JSONифицирует тело перед отправкой.

Отправка этого (необработанного тела GraphQL) в виде JSON:

query{repository(owner:"ccjmk", name:"super-happiness"){object(expression:"master"){... on Commit{history{totalCount}}}}}

Возвращает 400 неверных запросов:

{
    "message": "Problems parsing JSON",
    "documentation_url": "https://developer.github.com/v4"
}

... где вместо этого, если вы отправите его, отправьте его как тело, закодированное в a JSON, поскольку документация требует :

{"query":"query{repository(owner:\"ccjmk\", name:\"super-happiness\"){object(expression:\"master\"){... on Commit{history{totalCount}}}}}"}

Он отвечает ожидаемым 200 OK и JSON данным:

{
    "data": {
        "repository": {
            "object": {
                "history": {
                    "totalCount": 19
                }
            }
        }
    }
}
...