如何在REST API POST请求中发送HTML文件内容?

时间:2019-07-08 12:39:32

标签: python rest

我试图在python脚本的POST请求中发送HTML文件。

html_source = """
        <html>
        <head>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
        </head>
        <body>
        <table class="sstable table-bordered inner-table">
        <tr>
        <th>ID</th>
        <th>Title</th>
        </tr>
        <tr>
        <td>T01</td>
        <td>Title 1</td>
        </tr>
          <tr>
        <td>T02</td>
        <td>Title 2</td>
        </tr>
          <tr>
        <td>T03</td>
        <td>Title 3</td>
        </tr>
        </table>
        </body
        </html>
        """
auth_values = ('usernae','password')    
data = '{"name":"Some Widget","dashboardId":7,"type":"text","content":' '"' +html_source+ '"''}'
url = "company.com/api"
response = requests.post(url, data=data, auth=auth_values)

print ('Response Status:',response.status_code)
print ('Response Body:',response.content)

但是,该请求给出了以下响应:

('Response Status:', 200)
('Response Body:', '{"data":null,"errmsg":"Invalid json body","status":1007}')

是因为我尝试传递HTML字符串的方式吗?我尝试转义HTML,但仍然无法正常工作。

是否可以将"content":指向系统中的HTML文件?

0 个答案:

没有答案