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
Regular Contributor
Posts: 73
Registered: ‎12-30-2011
My Device: All devices
My Carrier: RIM
Accepted Solution

How to set request header

Hi Everyone,


Please help me i am trying to download image from server, but to download image need to set request header to download image please tell how can i set request header value. I am using following code but it is not working.

 

QNetworkRequest request = QNetworkRequest();
request.setUrl(QUrl(url));
QString value ="PVR_CINEMAS/1.0(1;7.0;9900;3;480*640)";
QString userAgent= "User-Agent: ";
request.setRawHeader(uname.toLocal8Bit().toBase64().toLower(),userAgent.toLocal8Bit().toBase64().toLower());
mNetworkAccessManager->get(request);

 

 

 

 

 

Thanks

Mohd Farhan
Regular Contributor
Posts: 73
Registered: ‎12-30-2011
My Device: All devices
My Carrier: RIM

Re: How to set request header

[ Edited ]

hi

 

I am using like this

 

        QNetworkRequest request = QNetworkRequest();
        request.setUrl(QUrl("http://xxx.xx.92.38:xxxx/ws/PvrCinemaService.svc/artwork/FFFFFFFF"));
       
        request.setRawHeader(QString("Content-Type:").toUtf8(),QString("application/json").toUtf8());
        request.setRawHeader(QString("Accept:").toUtf8(),QString("application/json").toUtf8());
        request.setRawHeader(QString("User-Agent:").toUtf8(),QString("PVR_CINEMAS/1.0 (1; 10.0; 9900; 1; 320*480)").toUtf8());


        mNetworkAccessManager->get(request);

 

 

I get always network error 400 bad-request , please tell me what is worng with it, when i check it on FIddler then working fine.

Thanks

Mohd Farhan
Highlighted
Regular Contributor
Posts: 73
Registered: ‎12-30-2011
My Device: All devices
My Carrier: RIM

Re: How to set request header

[ Edited ]

I got the solution, i was doing little bit mistake in my code right one is given below

 

request.setRawHeader(QString("Content-Type:").toUtf8(),QString("application/json").toUtf8());
request.setRawHeader(QString("Accept:").toUtf8(),QString("application/json").toUtf8());
request.setRawHeader(QString("User-Agent:").toUtf8(),QString("PVR_CINEMAS/1.0 (1; 10.0; 9900; 1;320*480)").toUtf8());

 

 

"Content-Type:"  -->  "Content-Type"   

  "Accept:"  ---->   "Accept"

 

i just removed colon

Thanks

Mohd Farhan