7

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.

6
  • 1
    Could you post what it returns? Commented Oct 4, 2012 at 6:55
  • If CI is not necessary you could give a chance to jabsorb. Commented Oct 31, 2012 at 10:07
  • simply try a URL first, from a console java app and proceed from there. Commented Dec 15, 2012 at 7:08
  • 1
    try using a client like Advanced REST Client (chrome.google.com/webstore/detail/advanced-rest-client/…) to see what the server returns. if you can post the response header it will be a lot helpful Commented Jan 9, 2013 at 12:02
  • Try poster, addons.mozilla.org/en-us/firefox/addon/poster or SOAP UI soapui.org to test your REST request/response. You could even use CURL from the command like if you are on a *NIX machine. Doing this will validate the information you are requesting is available and you can troubleshoot more from there. Commented Feb 27, 2013 at 21:09

1 Answer 1

1

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);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.