Russian Qt Forum

Qt => Работа с сетью => Тема начата: Sahab от Ноябрь 09, 2009, 14:48



Название: QHttp и 'PUT'
Отправлено: Sahab от Ноябрь 09, 2009, 14:48
Код:
void as3Core::putObject( QString path )
{
QCryptographicHash qhs(QCryptographicHash::Md5);

// hash (MD5) файла
QFile file(path);
if (!file.open(QIODevice::ReadOnly)) {
return;
}
char bytes [1024];
while(!file.atEnd()) {
int nBlocksize = file.read(bytes, sizeof(bytes));
qhs.addData(bytes, nBlocksize);
}
QByteArray hash = qhs.result().toBase64();
file.close();

int size = file.size();
QString currentDateTime = getCurrentTime();

QHttpRequestHeader header("PUT", "/" + path);
header.setValue("Host",host);

header.setContentLength(size);
header.setValue("Content-MD5", hash);
header.setValue("Content-Type", "binary/octet-stream");
header.setValue("Date", currentDateTime);
header.setValue("x-amz-acl", "private");
QByteArray signature = restCreateSignature(header);
header.setValue("Authorization", "AWS " + keyID + ":" + signature);

http->setHost(host);
http->request(header);
}

запрос не отправляется
WireShark показывает только ответ сервера - "Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed."
error - false / NoError
почему не отправляется запрос?


Название: Re: QHttp и 'PUT'
Отправлено: Sahab от Ноябрь 09, 2009, 14:54
если убрать Content-Length то запрос отправляется, но серверу он необходим - "You must provide the Content-Length HTTP header."
//header.setContentLength(size);



Название: Re: QHttp и 'PUT'
Отправлено: BRE от Ноябрь 09, 2009, 15:12
А размер верный возвращается?
int size = file.size();


Название: Re: QHttp и 'PUT'
Отправлено: Sahab от Ноябрь 09, 2009, 17:05
да.
Кстати. Баг ли, не знаю. Если допустим установить значение хедера через setValue (или setContentLength в частности), а после этого вызвать метод setValues(QList...)(другие хедеры, content-type, например) то установленные раннее значение исчезают