拦截post数据

This commit is contained in:
Irony 2019-10-01 21:39:27 +08:00
parent 9d641744b1
commit 1dfc61ddbb
3 changed files with 11 additions and 3 deletions

View file

@ -5,7 +5,7 @@
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.5 (venv) (6)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.5" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">

View file

@ -56,5 +56,5 @@
</profile-state>
</entry>
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.5 (venv) (6)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.5" project-jdk-type="Python SDK" />
</project>

View file

@ -9,7 +9,7 @@ Created on 2019年9月24日
@file: QWebView.BlockAds
@description: 拦截请求
"""
from PyQt5.QtCore import QUrl
from PyQt5.QtCore import QUrl, QBuffer, QByteArray
from PyQt5.QtNetwork import QNetworkAccessManager
from PyQt5.QtWebKitWidgets import QWebView
@ -32,6 +32,14 @@ class RequestInterceptor(QNetworkAccessManager):
# 拦截百度联盟的广告
print('block:', url)
originalReq.setUrl(QUrl())
if op == self.PostOperation and outgoingData:
# 拦截或者修改post数据
# 读取后要重新设置,不然网站接收不到请求
data = outgoingData.readAll().data()
print('post data:', data)
# 修改data后重新设置
outgoingData = QBuffer(self)
outgoingData.setData(data)
return super(RequestInterceptor, self).createRequest(op, originalReq, outgoingData)