qt HTTP Basic Authentication认证

HTTP Basic Authentication认证方式:
在http头中添加,Authorization属性。
http head 格式:

POST http://117.48.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Accept-Encoding: gzip,deflate
Content-Type: application/json
Authorization: Basic eW91cmFwcC1uYW1lOnlvdXJhcHAtcGFzc3dvcmQ=
Content-Length: 614
Host: 117.48.xxxxxxxxxx
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

Authorization: “Basic 用户名:密码(base64加密字符串)”
Authorization: Basic eW91cmFwcC1uYW1lOnlvdXJhcHAtcGFzc3dvcmQ=

 QNetworkRequest request;
 request.setUrl(QUrl(url));
 request.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/json;charset=utf-8"));
 request.setRawHeader("Authorization","Basic eW91cmFwcC1uYW1lOnlvdXJhcHAtcGFzc3dvcmQ=");//Authorization身份验证

QNetworkAccessManager* netWork = new QNetworkAccessManager(this);
QString sendStr;//发送内容
netWork->post(request, sendStr.toUtf8().constData());

你可能感兴趣的:(QT,qt,HTTP,Basic,Authentication)