[英]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.