Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
tnavabothu
Posts: 48
Registered: ‎08-07-2013
My Device: z10

Qmultipart/form-data post request,server response bad request

[ Edited ]

hi 

 i'm using the following code to send a Qmultipart form-data post request to send a zip file to server, in response the server returns a response code 299,when i print the error it shows bad request.

     

QString filepath;
QTextStream(&filepath)<<QString(QDir::currentPath()+"/data/doodle.zip");
QFile *file = new QFile(filepath);
file->open(QIODevice::ReadOnly);
QByteArray loadedArray = file->readAll();
// Setting header for multipart request
QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QHttpPart userid;
userid.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("multipart/form-data"));
userid.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=sender_unique_id"));
userid.setBody("7a5acbf7-31ea-431e-9404-8ebf35661124");
QHttpPart platform;
platform.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("multipart/form-data"));
platform.setHeader(QNetworkRequest::ContentDispositionHeader,QVariant("form-data;name=sender_platform"));
platform.setBody("BLACKBERRY");
QHttpPart jsonobj;
jsonobj.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("text/json"));
jsonobj.setHeader(QNetworkRequest::ContentDispositionHeader,QVariant("form-data;name=receiver_json"));
jsonobj.setBody("{\"provider\":\"PHONE\", \"phone_number\":\"9491709339\", \"country_code\":\"91\"}");
QHttpPart content;
content.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/zip"));
content.setHeader(QNetworkRequest::ContentDispositionHeader,QVariant("form-data;name=content"));
//content.setBodyDevice(file);
content.setBody(file->readAll());
//file->setParent(multiPart);
QHttpPart sendtype;
sendtype.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("multipart/form-data"));
sendtype.setHeader(QNetworkRequest::ContentDispositionHeader,QVariant("form-data;name=send_type"));
sendtype.setBody("SEND");
multiPart->append(userid);
multiPart->append(platform);
multiPart->append(jsonobj);
multiPart->append(content);
multiPart->append(sendtype);

//7a5acbf7-31ea-431e-9404-8ebf35661124; sender_platform=ANDROID;receiver_json='[{\"provider\":\"PHONE\", \"phone_number\":\"9059809201\", \"country_code\":\"91\"}]';send_type=SEND;content="+loadedArray+""));
//multiPart->append(zipPart);
QUrl url("http://xxxxxxxxx");
QNetworkRequest request(url);
//QDir jk(QDir::currentPath()+"/data");


QNetworkAccessManager *manager=new QNetworkAccessManager(this);
QNetworkReply *reply = manager->post(request, multiPart);
multiPart->setParent(reply);


connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
qDebug()<<"request sent";

 

 

 can any one help me to sort it out..\

 

thank you,

Contributor
tnavabothu
Posts: 48
Registered: ‎08-07-2013
My Device: z10

Re: Qmultipart/form-data post request,server response bad request

Hi,

Is there any one who can help me

thank u