简体   繁体   English

如何使用GET方法设置http标头“接受”

[英]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. 我无法通过GET http请求获取JSON内容。 I got the html/text content, even when I try to specify the "Accept" http header in my request. 即使我尝试在请求中指定“ Accept” http标头,我也得到了html / text内容。

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. 大多数库只希望标头名称,而没有冒号或空格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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