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
EkanshSrivastava
Posts: 49
Registered: ‎08-13-2012
My Device: 9300
My Carrier: Airtel

Not Acceptable status: 406

Hi All,

 

I am trying to make request to a server but its replying the following error. I am stuck into it.. :

 

Debug: "Error: Error downloading https://someurl.com/staffapi/index.php?/Core/Default/Login - server replied: Not Acceptable status: 406" 

 

Any help will be appreciated.

 

 

Thanks

Ekansh

Please use plain text.
Developer
kamalakshan
Posts: 107
Registered: ‎06-12-2012
My Device: Dev Alpha C, Playbook
My Carrier: Loop

Re: Not Acceptable status: 406

Here is the explanation

http://www.checkupdown.com/status/E406.html
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
Please use plain text.
Developer
simon_hain
Posts: 15,806
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Not Acceptable status: 406

do you set an acceptable content-type in your request?
check the status message of the server, maybe it replies with the correct content types.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
EkanshSrivastava
Posts: 49
Registered: ‎08-13-2012
My Device: 9300
My Carrier: Airtel

Re: Not Acceptable status: 406

HI Kamalakshan,

I've already gone through that before posting here.

Thanks
Ekansh
Please use plain text.
Contributor
EkanshSrivastava
Posts: 49
Registered: ‎08-13-2012
My Device: 9300
My Carrier: Airtel

Re: Not Acceptable status: 406

Hi Simon,

No I did't put any content type in request.

Thanks
Ekansh
Please use plain text.
Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)
My Carrier: Mobile Vikings

Re: Not Acceptable status: 406

Can you show your code where you make the network request?

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Please use plain text.
BlackBerry Development Advisor (Retired)
garydev
Posts: 83
Registered: ‎10-10-2012
My Device: Z30
My Carrier: Bell

Re: Not Acceptable status: 406

Hi EkanshSrivastava

 

As zezke writes - can you please post your code.

 

Thanks,

 

g

Please use plain text.
Contributor
EkanshSrivastava
Posts: 49
Registered: ‎08-13-2012
My Device: 9300
My Carrier: Airtel

Re: Not Acceptable status: 406

void NetworkConnect::initRequest(QString URL, QByteArray param) {

	QNetworkRequest request = QNetworkRequest();

	// For your "Content-Length" header
	QByteArray postDataSize = QByteArray::number(param.size());
	request.setUrl(QUrl(URL));
	request.setHeader(QNetworkRequest::ContentTypeHeader,
			"application/x-www-form-urlencoded");
	mNetAccessMngr->post(request, param);
}


void NetworkConnect::HandleBtnLoginClick(QString helpdeskUrl, QString username,
		QString password) {

	GlobalValue obj;
	obj.setHelpdeskURL(helpdeskUrl);
	obj.setUsername(username);
	obj.setPassword(password);

	iCase = 0;
	QByteArray byteArrayObject;

	byteArrayObject.append("username=" + username + "&");
	byteArrayObject.append("password=" + password + "");

	qDebug() << "Data Sent :: " << QString::fromAscii(byteArrayObject);


	int start = obj.getLoginUrl().indexOf("http", 0, Qt::CaseInsensitive);
	if (start > -1) {
		initRequest("" + obj.getLoginUrl(), byteArrayObject);
		qDebug() << "Login URL :: " << "" + obj.getLoginUrl();
	} else {
		initRequest("http://" + obj.getLoginUrl(), byteArrayObject);
		qDebug() << "Login URL :: " << "http://" + obj.getLoginUrl();
	}

	bool result = connect(mNetAccessMngr, SIGNAL(finished(QNetworkReply*)),
			this, SLOT(requestFinished(QNetworkReply*)));
	Q_ASSERT (result);
	Q_UNUSED(result);
}



void NetworkConnect::requestFinished(QNetworkReply* reply) {
	response = "";
	if (reply->error() == QNetworkReply::NoError) {

		const int available = reply->bytesAvailable();
		if (available > 0) {
			const QByteArray buffer(reply->readAll());
			response = QString::fromUtf8(buffer);
			qDebug() << "Response is -- " << response;
			isSuccess = true;
			fncHandleResponse(iCase);
		}

	} else {
		response =
				tr("Error: %1 status: %2").arg(reply->errorString(),
						reply->attribute(
								QNetworkRequest::HttpStatusCodeAttribute).toString());
		qDebug() << response;

		QObject *lblError = bb::cascades::Application::instance()->findChild<
				QObject*>("objLabelError");

		if (lblError)
			lblError->setProperty("text", response);
		iCase = -1;
		isSuccess = false;
		fncHandleResponse(iCase);
	}
	reply->deleteLater();

	if (response.trimmed().isEmpty()) {
		response = tr("Unable to retrieve post response");
	}
	Dialog *popUpDialog = bb::cascades::Application::instance()->findChild<
			Dialog*>("objLoadingPop");
	popUpDialog->close();

}

 

Hi,

 

I am using the above three methods to make connection and parse.

 

Thanks

Ekansh

Please use plain text.
Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)
My Carrier: Mobile Vikings

Re: Not Acceptable status: 406

[ Edited ]

You seem to do a POST request in a very different way than me. Here's how I do it:

 

	QUrl url("http://www.url.country/api");
	//Prepare parameters
	QUrl params;
	params.addQueryItem("key", Information::getSessionToken());
	params.addQueryItem("modafter", QString::number(modAfter));
	params.addQueryItem("fields", QString("folder,context"));
	params.addQueryItem("f", "xml");
	QByteArray data;
	data = params.encodedQuery();
	//Prepare request
	QNetworkRequest request;
	request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
	request.setUrl(url);
	//Execute request
	networkManager->post(request, data);

 Especially the way you setup the parameters seems weird and incorrect at first glance.

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Please use plain text.
Contributor
EkanshSrivastava
Posts: 49
Registered: ‎08-13-2012
My Device: 9300
My Carrier: Airtel

Re: Not Acceptable status: 406

HI zezke,

 

Its the same with different way.

 

Thanks

E

Please use plain text.