如何在 bb 级联中使用 QNetWorkRequest 的身份验证详细信息



我想使用 bb 级联创建一个 BB10 应用程序,其中我想通过 QNetWork http 请求将用户名和密码传递给服务器。我尝试了以下方法

QNetworkRequest request = QNetworkRequest();
request.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
request.setRawHeader("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
request.setRawHeader("Content-Language", "en-US");
QString concatenated = "username:password";
QByteArray data = concatenated.toLocal8Bit().toBase64();
QString headerData = "Basic " + data;
req.setRawHeader("Authorization", headerData.toLocal8Bit());
QSslConfiguration config = request.sslConfiguration();
config.setPeerVerifyMode(QSslSocket::VerifyNone);
config.setProtocol(QSsl::TlsV1);
request.setSslConfiguration(config);

但这给了我一个QNetworkRepred错误202(ContentOperationNotPermittedError)。此错误的原因是什么?如何解决此问题?

提前致谢

这段代码对我有用

QNetworkRequest request = QNetworkRequest();
request.setRawHeader("Authorization","Basic " +   QByteArray(QString("%1:%2").arg(USER_NAME).arg(PASSWORD).toAscii()).toBase64());
request.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
request.setRawHeader("Content-Language", "en-US");
QSslConfiguration config = request.sslConfiguration();
config.setPeerVerifyMode(QSslSocket::VerifyNone);
config.setProtocol(QSsl::TlsV1);
request.setSslConfiguration(config);

相关内容

  • 没有找到相关文章

最新更新