要更改 qtwebkit 中的 POST 变量,需要更改或替换 createRequest(...) 中的输出数据。如何创建自己的<PyQt4.QtCore.QIODevice object at 0x03BA...>
不是 QFile 或 QByteArray。正是 QIODevice 对象!创建可写设备需要它。或者如何转换<PyQt4.QtCore.QBuffer object at 0x03BA...>
为<PyQt4.QtCore.QIODevice object at 0x03BA...>
.
QNetworkAccessManager中最常用的这个设备:
https ://qt.gitorious.org/qt/webkit/source/7647fdaf9a4b526581e02fbd0e87c41a96cbfebb:src/network/access/qnetworkaccessmanager.cpp#L941
QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Operation op,
const QNetworkRequest &req,
QIODevice *outgoingData)
...
更新:调用此方法后:
def createRequest(manager, operation, request, data):
if data.size() > 0:
post_body = "q=hello"
output = QtCore.QByteArray()
buffer = QtCore.QBuffer(output)
buffer.open(QtCore.QIODevice.ReadWrite)
buffer.writeData(post_body)
data = buffer
reply = QNetworkAccessManager.createRequest(manager, operation, request, data)
return reply
脚本挂了……