簡體   English   中英

按名稱值讀取原始http請求

[英]Reading raw http request by name value

給定下面的數據,我正在嘗試按名稱獲取每個content-disposition的值。 例如,獲取主題或值。 例如,我希望能夠查找“ html”,它將給我:

<html><body><strong>Hello SendGrid!</body></html>

我不確定該怎么做? 有這樣的想法:

subject = full_msg [full_msg.find('Content-Disposition:form-data; name =“ subject”')+ len('Content-Disposition:form-data; name =“ subject”'):full_msg.rfind('- -xYzZY')]。strip()

--xYzZY
Content-Disposition: form-data; name="headers"

MIME-Version: 1.0
Received: by 0.0.0.0 with HTTP; Wed, 10 Aug 2016 18:10:13 -0700 (PDT)
From: Example User <test@example.com>
Date: Wed, 10 Aug 2016 18:10:13 -0700
Subject: Inbound Parse Test Data
To: inbound@inbound.example.com
Content-Type: multipart/alternative; boundary=001a113df448cad2d00539c16e89

--xYzZY
Content-Disposition: form-data; name="dkim"

{@sendgrid.com : pass}
--xYzZY
Content-Disposition: form-data; name="to"

inbound@inbound.example.com
--xYzZY
Content-Disposition: form-data; name="html"

<html><body><strong>Hello SendGrid!</body></html>

--xYzZY
Content-Disposition: form-data; name="from"

Example User <test@example.com>
--xYzZY
Content-Disposition: form-data; name="text"

Hello SendGrid!

--xYzZY
Content-Disposition: form-data; name="sender_ip"

0.0.0.0
--xYzZY
Content-Disposition: form-data; name="envelope"

{"to":["inbound@inbound.example.com"],"from":"test@example.com"}
--xYzZY
Content-Disposition: form-data; name="attachments"

0
--xYzZY
Content-Disposition: form-data; name="subject"

Testing non-raw
--xYzZY
Content-Disposition: form-data; name="charsets"

{"to":"UTF-8","html":"UTF-8","subject":"UTF-8","from":"UTF-8","text":"UTF-8"}
--xYzZY
Content-Disposition: form-data; name="SPF"

pass
--xYzZY--
import email

full_msg = request.POST['email']
msg = email.message_from_string(full_msg)
from_address = msg["from"]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM