2 qq 33551148 qq_33551148 于 2016.05.05 15:41 提问

qt http post 上传出问题

//上传文件到linux服务器上
void Widget::on_pushButton_2_clicked()
{
QString UrlFilePath = ""; //服务器放置上传文件地址路径
QString filePath = ui->lineEdit_2->text(); //本地将要上传的文件路径
QFileInfo info(filePath);
file = new QFile(filePath);
QString fileName = info.fileName();
if(!file->open(QIODevice::ReadOnly))
{
qDebug() << "file open error";
delete file;
file = NULL;
}
int file_len = file->size();
// QByteArray data = file->readAll();
QDataStream in(file);
m_buf = new char[file_len];
if(in.readRawData(m_buf,file_len)!=file_len){
qWarning("文件读取不完整readRaw");
}
file->close();
delete file;
file = NULL;
UrlFilePath = QString("http://192.168.2.1/images/advertise/%1").arg(fileName);
// UrlFilePath = QString("http://192.168.2.1/images/advertise/");
url.clear();
//准备路径地址
url.setUrl(UrlFilePath);
//准备数据
QByteArray arr = QByteArray(m_buf,file_len);
/*****连接实现*****/
QNetworkRequest request = QNetworkRequest(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
request.setHeader(QNetworkRequest::ContentLengthHeader,QVariant(arr.size()));
reply = manager->post(request,arr); //QNetworkReply reply指针
//上传关联信号
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(upLoadError(QNetworkReply::NetworkError)));

//上传完成后
connect(reply,SIGNAL(finished()),this,SLOT(httpFinished()));
//更新进度条
connect(reply,SIGNAL(uploadProgress(qint64,qint64)),this,SLOT(updateDataReadProgress(qint64 ,qint64)));
ui->progressBar->setValue(0);
//显示进度条
ui->progressBar->show();

}

1个回答

qq_33551148
qq_33551148   2016.05.05 15:43

哪位 大哥能帮小弟看看上传实现的哪有问题,下载是可以实现了,但是上传不了?没分了谢谢各位大大帮忙了,小弟菜鸟一个。。。。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!