简体   繁体   中英

How to set the http header “Accept” for a GET method with

I can't manage to get the JSON content with a GET http request. I got the html/text content, even when I try to specify the "Accept" http header in my request.

URI uri = new org.apache.http.client.utils.URIBuilder(url)
        .setParameter("departureLat", "601718")
        .setParameter("departureLng", "2414450")
        .setParameter("arrivalLat", "600797")
        .setParameter("arrivalLng", "2429000")
        .build();
Request request = Request.Get(uri)
        .connectTimeout(5000)
        .addHeader("Accept: ", String.valueOf(ContentType.APPLICATION_JSON))
        .socketTimeout(timeout);
HttpResponse response = JsonTools.execute(service, uri, request, content);

Any idea ? :)

Try:

    .addHeader("Accept", String.valueOf(ContentType.APPLICATION_JSON))

Most libraries expect the header name alone, without the colon or space.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM