除非您有某种方法将响应(这里是HTML假定的)转换为.doc文件,否则您将获得的只是一个包含扩展名为.doc的响应的文本文件。如果您愿意使用.docx文件,那么有个很棒的python库叫做python- docx,您应该研究一下它,它允许您使用lxml库生成格式正确的docx文件。
或者,使用模板,例如:
<html>
<head>
<Meta HTTP-EQUIV=""Content-Type"" CONTENT=""text/html; charset=UTF-8"">
<Meta name=ProgId content=Word.Document>
<Meta name=Generator content=""Microsoft Word 9"">
<Meta name=Originator content=""Microsoft Word 9"">
<style>
@page Section1 {size:595.45pt 841.7pt; margin:1.0in 1.25in 1.0in 1.25in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}
div.Section1 {page:Section1;}
@page Section2 {size:841.7pt 595.45pt;mso-page-orientation:landscape;margin:1.25in 1.0in 1.25in 1.0in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}
div.Section2 {page:Section2;}
</style>
</head>
<body>
<div class=Section2>
'Section1: Portrait, Section2: Landscape
[your text here]
</div>
</body>
</html>
根据此asp.net论坛帖子,当application/msword
使用UTF-8
charset作为mime类型返回时,这应该创建一个有效的.doc文件(因此,请确保字符串均为unicode)。