We built our API using Phil Sturgeons cool Restful API framework for codeigniter, which is production ready and is used as part of our mobile apps implementation.
We have an issue when using the API in Java
httpConnection = (HttpConnection) Connector.open(url, Connector.READ, true);
// Set content type by given parameter......
httpConnection.setRequestProperty("Accept", contentType);
httpConnection.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/FCLDC-1.0");
httpConnection.setRequestProperty("Content-Type", contentType);
httpConnection.setRequestProperty("TK-API-KEY", UrlFactory.TK_API_KEY);
// httpConnection.setRequestProperty("Model",
// StyleUtil.getDeviceModel());
if (httpConnection.getResponseCode() == 302)
{
String redirectUrl = httpConnection.getHeaderField("Location");
httpConnection = (HttpConnection) Connector.open(redirectUrl, Connector.READ_WRITE, true);
}
if (httpConnection.getResponseCode() == HttpConnection.HTTP_OK)
{
io = httpConnection.openInputStream();
int ch;
while ((ch = io.read()) != -1)
{
bo.write(ch);
}
}
httpConnection.getResponseCode()
is unable to get the status code and returns a malformed exception. Our API server is NGINX.
MalformedException is thrown in case header fields are not set properly. Please check with different headers and also with different user agents. Trying using httpConnection.setDoOutput(true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With