I'm trying to send a JSON query to a web service and I continue to get internal server errors as a response to the query.
Here is what I'm trying to send:
POST /api/1.7/webservice.asmx HTTP/1.1
Host: www.superService.com
User-Agent: My app name v0.1
X-Custom-User-Agent: My app name v0.1
Content-Type: application/json
Content-Length:81
{"method":"AuthenticatePlain","loginName":"[email protected]","password":"mypass"}
This is supposed to be sent to https://www.superService.com/api/1.7/ssapi.asmx
In preparing the QNetworkRequest
, what method is used to insert the line
POST /api/1.7/webservice.asmx HTTP/1.1?
Is the complete header contained in the QNetworkRequest
object?
Should the JSON data be in the QNetworkRequest
object or is that added to the post as the second argument in the QNetworkAccessManager::post()
method?
Here is my current code in the on_btnLogin_clicked()
slot:
connect(m_qnam, SIGNAL(finished(QNetworkReply*)),
this, SLOT(handleNetworkData(QNetworkReply*)));
connect(m_qnam,SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
this, SLOT(handleSSLErrors(QNetworkReply*)));
QString baseString = "";
baseString.append(QString("POST /api/1.7/webservice.asmx HTTP/1.1
").toUtf8());
baseString.append(QString("www.superService.com
").toUtf8());
baseString.append(QString("User-Agent: My app name v0.1
").toUtf8());
baseString.append(QString("X-Custom-User-Agent: My app name v0.1
").toUtf8());
baseString.append(QString("Content-Type: application/json
").toUtf8());
QString jsonString = QString("{");
jsonString.append(""method":");
jsonString.append(""AuthenticatePlain"");
jsonString.append(","loginName":");
jsonString.append(""[email protected]"");
jsonString.append(","password":");
jsonString.append(""mypass"");
jsonString.append("}");
QByteArray json = jsonString.toUtf8();
baseString.append(QString("Content-Length:").toUtf8());
baseString.append(QString::number(json.length()));
baseString.append("
").toUtf8();
baseString.append(QString("
").toUtf8());
baseString.append(json);
request = QNetworkRequest(QUrl("https://www.superService.com/api/1.7/ssapi.asmx"));
request.setRawHeader()
qDebug() << "Base String: "<< baseString;
m_qnam->post(request,baseString.toUtf8());
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…