Клиент Джерси - отправка запроса с ошибкой «Заголовок типа контента должен быть application / vnd.api + json» - PullRequest
0 голосов
/ 28 февраля 2020

Я пытаюсь протестировать пост-запрос, используя клиент jersey, хотя я устанавливаю заголовок, как показано ниже, в ответ я получаю сообщение об ошибке, что заголовок Content-Type должен быть application / vnd.api + json. Пожалуйста, обратитесь ниже код:

String input = "{\r\n" + 
                "  \"data\": {\r\n" + 
                "    \"attributes\": {\r\n" + 
                "      \"email\": \"emailqwszxwe@example.com\",\r\n" + 
                "      \"password\": \"password\",\r\n" + 
                "      \"avatar_url\": \"http://example.com/example.png\",\r\n" + 
                "      \"first-name\": \"John\",\r\n" + 
                "      \"last-name\": \"Doe\",\r\n" + 
                "      \"details\": \"example\",\r\n" + 
                "      \"contact\": \"example\",\r\n" + 
                "      \"facebook-url\": \"http://facebook.com/facebook\",\r\n" + 
                "      \"twitter-url\": \"http://twitter.com/twitter\",\r\n" + 
                "      \"instagram-url\": \"http://instagram.com/instagram\",\r\n" + 
                "      \"google-plus-url\": \"http://plus.google.com/plus.google\",\r\n" + 
                "      \"original-image-url\": \"https://cdn.pixabay.com/photo/2013/11/23/16/25/birds-216412_1280.jpg\"\r\n" + 
                "    },\r\n" + 
                "    \"type\": \"user\"\r\n" + 
                "  }\r\n" + 
                "}";
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target("http://qe.events.infostretch.com/api");

    String content = "application/vnd.api+json";
    Response response = target.path("/v1/users").request().header("Content-Type", content).post(Entity.json(input));

Выход:

{"errors": [{"source": "", "detail": "Content-Type header must be application/vnd.api+json", "title": "InvalidRequestHeader", "status": 415}], "jsonapi": {"version": "1.0"}}```

I am not able to understand why it is not showing correct response???

i am using below dependency:

<dependency> <groupId>org.glassfish.jersey.core</groupId> 
<artifactId>jersey-client</artifactId> 
<version>2.30.1</version> </dependency>

...