您好我想要提供我内容的纯文本版本.所以我有一个单独的模板.我打电话render_to_response用mimetype="text/plain",但我想告诉浏览器中打开该页面的HTTP响应内容是UTF-8编码.我该怎么做(例如我需要添加什么render_to_response)?
我有一个使用REST API的项目.在Isend登录请求时,他们发送响应作为JSON包含一些数据.与响应标题中的一起
Access-Control-Allow-Origin:*
Connection:keep-alive
Content-Length:239
Content-Type:application/json
Date:Fri, 19 Oct 2012 06:28:12 GMT
Server:Apache/2.2.22 (Amazon)
Set-Cookie:session=username; Path=/
Run Code Online (Sandbox Code Playgroud)
这里我们有一个Set-Cookie,但这个cookie没有设置.我需要设置此cookie,因为对于任何其他API访问,服务器将检查此cookie.
我该如何解决这个问题?jQuery AJAX响应Header Set-Cookie方法的解决方案是什么?
我有以下方法在HttpResponse对象中写入流.
public HttpResponse ShowPDF(Stream stream)
{
MemoryStream memoryStream = (MemoryStream) stream;
httpResponse.Clear();
httpResponse.Buffer = true;
httpResponse.ContentType = "application/pdf";
httpResponse.BinaryWrite(memoryStream.ToArray());
httpResponse.End();
return httpResponse;
}
Run Code Online (Sandbox Code Playgroud)
为了测试它,我需要恢复处理过的流.有没有办法从httpResponse对象读取流?
我正在使用Spring 3.0.1.RELEASE为我的webapp(我无法升级它),我正在尝试从网页上的数据库渲染一些图像.
我有以下简单的Spring配置:
弹簧的application.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<task:annotation-driven />
<context:annotation-config />
<context:spring-configured />
<context:component-scan base-package="com.me" />
<bean id="hibernateSessionFactory" class="com.me.dbaccess.HibernateSessionFactory">
<constructor-arg ref="sessionFactory"/>
</bean>
</beans>
Run Code Online (Sandbox Code Playgroud)
弹簧mvc.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<mvc:annotation-driven/>
<bean id="tilesViewResolver" class="com.me.util.TilesExposingBeansViewResolver">
<property name="viewClass" value="com.me.util.TilesExposingBeansView"/>
<property name="exposeContextBeansAsAttributes" value="true"/>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/config/tiles-defs.xml</value>
</list>
</property>
</bean>
</beans>
Run Code Online (Sandbox Code Playgroud)
我有以下控制器:
@Controller
public class PhotoController {
@RequestMapping("/carPhoto.html")
@ResponseBody
public byte[] getCarPhoto(
@RequestParam(UrlParameters.PHOTO_ID) Integer photoId,
@RequestParam(UrlParameters.PHOTO_TYPE) …Run Code Online (Sandbox Code Playgroud) 我必须从远程服务器获取一些JSON对象,为此我正在使用这个功能很好,除了有时一些奇怪的数据被提取,我相信是因为它使用ASCII字符集进行解码.
请在下面找到我正在使用的方法
public HttpResponse call(String serviceURL,String serviceHost,String namespace,String methodName,String payloadKey, String payloadValue) throws ClientProtocolException,IOException,JSONException
{
HttpResponse response = null;
HttpContext HTTP_CONTEXT = new BasicHttpContext();
HTTP_CONTEXT.setAttribute(CoreProtocolPNames.USER_AGENT, "Mozilla/5.0");
HttpPost httppost = new HttpPost(serviceURL);
httppost.setHeader("User-Agent",Constants.USER_AGENT_BROWSER_FIREFOX);
httppost.setHeader("Accept", "application/json, text/javascript, */*");
httppost.setHeader("Accept-Language","en-US,en;q=0.8");
httppost.setHeader("Content-Encoding", "foo-1.0");
httppost.setHeader("Content-Type", "application/json; charset=UTF-8");
httppost.setHeader("X-Requested-With","XMLHttpRequest");
httppost.setHeader("Host",serviceHost);
httppost.setHeader("X-Foo-Target", String.format("%s.%s", namespace,methodName));
/*Making Payload*/
JSONObject objectForPayload = new JSONObject();
objectForPayload.put(payloadKey, payloadValue);
StringEntity stringentity = new StringEntity(objectForPayload.toString());
httppost.setEntity(stringentity);
response = client.execute(httppost);
return response;
}
Run Code Online (Sandbox Code Playgroud)
我传递的所有这些标题都是正确的,如果您熟悉Mozilla,我已通过Google Chrome或Firebug插件中的inspect元素验证了相同内容.
现在的问题是,大部分时间我都在获取可读数据,但有时我确实得到了不可读的数据.
我使用eclipse调试并注意到wrappedEntity下的charset显示为"US-ASCII".我附上一个jpg作为参考
有人可以告诉我如何在我之前将字符集从ASCII更改为UTF-8 response = client.execute(httppost);.PS:正如你已经注意到我在标题中传递charset = utf-8并且我已经使用firebug和谷歌浏览器验证我传递了确切的标题.
请放大以更清楚地查看图像 …
java http httpresponse character-encoding apache-httpclient-4.x
LinkedIn上的人们一直在以有趣的方式使用Play来处理需要由许多不同组件组成的页面:http://engineering.linkedin.com/play/composable-and-streamable-play-apps
他们如何做到的关键组成部分是Play中的"动作"返回完整的响应,因此能够通过更高级别的动作"组合"成另一个响应.
Grails似乎并没有真正从动作中返回任何东西(或者至少没有任何特定的东西),并且当你在一个动作中时,没有一种简单的方法可以调用另一个动作.
那么,Grails可以采用这种构图方式吗?
我最近发现我无法用PhantomJS读取ajax请求的响应主体.考虑到这个问题,看来这已经被踢了很长一段时间没有完全解决.我想知道PhantomJS项目是否由于某种原因而不想要这种能力,可能与资源有关.
有许多旧问题甚至是旧的PR来解决这个问题,但目前还不清楚这是否正在进展,停滞不前,项目维护人员不希望等等......问题:https://github.com/ariya/phantomjs/issues/10158 PR:https://github.com/ariya/phantomjs/pull/11484
有谁知道PhantomJS项目中此功能的状态?
我试图从我的servlet重定向到外部域url.但重定向增加了; jsessionid = ghdssdf ... 在url的末尾.我不知道如何防止将jsession id附加到我的网址.我的应用程序正在Websphere上运行
resp.sendRedirect(resp.encodeRedirectURL("https://www.facebook.com/mymage"));
Run Code Online (Sandbox Code Playgroud)
结束定向网址可以在浏览器中看到https://www.facebook.com/mymage;jsessionid=dfsdfsd
我有一个业务流程,它接收来自本地休息服务的请求然后发送请求到另一个远程Rest服务然后如果远程服务成功返回200个HTTP代码的响应BizTalk可以处理响应消息,但如果HTTP响应代码不同那么200 BizTalk无法处理故障响应消息.
BizTalk日志在事件查看器上给出以下错误.
Details:"System.Net.WebException: The remote server returned an unexpected response: (400) Bad Request.
{"errorMessage":{"message":"En az 1 adres alani gereklidir.","moreInfoURL":"http://paritus.com/kb/api-errors","status":400}}".
Run Code Online (Sandbox Code Playgroud)
在此问题之后,我在发送端口上添加了一个故障操作,但BizTalk仍然无法捕获失败消息.你有什么想法吗?
以下之间有什么区别
response.status(200).send('Hello World!');
Run Code Online (Sandbox Code Playgroud)
和这个
response.writeHead(200, {'content-type':'application/json'});
response.end('Hello World!');
Run Code Online (Sandbox Code Playgroud)
何时应使用以下哪项?