一旦部署应用程序,Google App Engine HTTP标头Content-Type不正确 [英] Google App Engine HTTP header Content-Type not correct once application is deployed
问题描述
我正在GAE上编写一个应用程序,并且我有一个始终返回XML并将Content-Type设置为text / xml; charset = utf-8的URL
。
我使用内置的webapp框架并使用以下代码来设置内容类型并在Web处理程序中返回XML:
self.response.headers.add_header('Content-Type',text / xml; charset = utf-8)
self.response.out。 write(template.render(my_xml,{key1:val1}))
这在本地开发环境中工作正常,但是一旦我部署到Google服务器,内容类型始终设置为text / html; charset = utf-8
。 p>
在Google服务器上运行后,如何确保设置正确的 Content-Type
?
使用 self.response.headers ['Content-Type'] =text / xml; charset = utf- 8
,以便覆盖内容类型而不是添加另一个同名头。
I am writing an app on GAE and I have a URL that will always return XML and set the Content-Type to "text/xml; charset=utf-8"
.
I am using the built in webapp framework and using the following code to set content type and return XML in the web handler:
self.response.headers.add_header('Content-Type',"text/xml; charset=utf-8")
self.response.out.write(template.render("my_xml",{"key1":"val1"}))
This works fine on the local development environment but once I deploy to the Google servers the content type is always set to "text/html; charset=utf-8"
.
How do I make sure that correct Content-Type
is set once it runs on the Google servers?
Use self.response.headers['Content-Type'] = "text/xml; charset=utf-8"
, so that you override the content-type rather than adding another homonymous header.
这篇关于一旦部署应用程序,Google App Engine HTTP标头Content-Type不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!