简体   繁体   English

通过服务进行的Http响应发送text / html中的内容(MIME)类型,但不是application / json

[英]Http response through service sends content (mime) type in text/html but not application/json

My application using Oauth for basecam api. 我的应用程序使用Oauth作为basecam api。 I am trying to get Httpresponse into json format but it revert into plain html (text/html) content-type. 我正在尝试将Httpresponse转换为json格式,但将其还原为纯html(text / html)内容类型。 so there is no method to parse HTML content and get the token from basecamp . 因此,没有方法可以解析HTML内容并从basecamp获取令牌。 This is not homework but a small R&D to quick start Oauth protocol. 这不是功课,而是一项小小的研发工作,可以快速启动Oauth协议。 as am new to oauth . 作为oauth新手。

//HERE -> final String JSON_CONTENT = "application/json"
String contentType = OAuthConstants.JSON_CONTENT;

    if (response.getEntity().getContentType() != null) {
        contentType = response.getEntity().getContentType().getValue();
        //BELOW -> getting contentType is in "text/html; utf-8
        System.out.println(response.getEntity().getContentType().getValue()); //text/html; charset=utf-8
    }

    if (contentType.contains(OAuthConstants.JSON_CONTENT)) {
        return handleJsonResponse(response);
    } else 
        if (contentType.contains(OAuthConstants.URL_ENCODED_CONTENT)) {
          return handleURLEncodedResponse(response);
        } else 
            if (contentType.contains(OAuthConstants.XML_CONTENT)) {
              return handleXMLResponse(response);
            }   
            else {
                // Unsupported Content type
                throw new RuntimeException(
                        "Cannot handle "
                                + contentType
                                + " content type. Supported content types include JSON, XML and URLEncoded");
            }

So above lines explain very well that control won't come is json, xml or url_encoded if-else. 因此,以上url_encoded行很好地说明了控制权不会是json,xml或url_encoded if-else。 Si either i need to parse text/html into json or xml response or i have to create another method name handleHtmlResponse() . 是要么我需要将text / html解析为json或xml响应,要么必须创建另一个方法名称handleHtmlResponse() what way it would be continent to get contentType . 大陆将以哪种方式获取contentType

在使用所有数据(标头,正文...)设置响应之后,通过调用ServletResponse#flushBuffer提交响应

暂无
暂无

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

相关问题 Http 响应 Content-Type 是 json。 “无效的 MIME 类型”错误 - Http response Content-Type is json. Error for "Invalid mime type" SSE `this.eventSource.onmessage` 调用失败。 错误`“EventSource 的响应具有不是“文本/事件流”的 MIME 类型(“application/json”) - SSE `this.eventSource.onmessage` call fails. Error `"EventSource's response has a MIME type ("application/json") that is not "text/event-stream" 预期的mime类型为application / xml,但有text / html - Expected mime type application/xml but got text/html Websphere Application Server 7中的HTTP标头Mime类型 - HTTP Header Mime Type in Websphere Application Server 7 提取类型 [class org.springframework.http.ResponseEntity] 和内容类型 [text/html;charset=UTF-8] 的响应时出错; - Error while extracting response for type [class org.springframework.http.ResponseEntity] and content type [text/html;charset=UTF-8]; 找不到适用于响应类型[..]和内容类型[application / json]的HttpMessageConverter - No suitable HttpMessageConverter found for response type [..] and content type [application/json] 如何从响应中找到 HTTP 媒体类型(MIME 类型)? - How to find HTTP Media Type (MIME type) from response? solr exception预期的mime类型application / octet-stream但是得到了text / html - solr exception Expected mime type application/octet-stream but got text/html 使用 Solr 索引文档导致预期的 MIME 类型应用程序/八位字节流但得到 text/html - Indexing documents using Solr results in Expected mime type application/octet-stream but got text/html 服务无法识别RestAssured内容类型application / json - RestAssured content-type application/json not being recognised by service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM