0

In my application i am trying to access 1 API which will return XML response.Now the problem is i am getting the response code from API ,but when i run the API straightly in web browser i am getting XML response.Whether the problem is in server side or in my code.Please help me.

Here is my code:

try{
//            System.out.println("b4 conn");
            HttpConnection conn = (HttpConnection)Connector.open(rssUrl);
            conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
            System.out.println("after conn="+conn.getResponseCode());                ---------->I am not getting the response here(so going to catch and closing the application).
            if(conn.getResponseCode()==HttpConnection.HTTP_OK)
            {

                Some stuff goes here.
            }
catch(Exception ex){
       // System.out.println("Error = "+ex);
        m.DisplayCloseAsk();

        }

Thanks in advance.

prakash .k
  • 625
  • 2
  • 12
  • 24
  • What's the problem? Can you plz be more clear? – Atul Goyal Aug 31 '12 at 08:50
  • Thanks Atul Goyal..I will explain my problem clear..Suppose consider reeURl in my code is"www.asdfg.com".When i called this API through my code as in my post i am receving any response code.But if i put this rssUrl in Browser it is returning 1 XML file.. – prakash .k Aug 31 '12 at 08:55
  • The XML file would contain the response right? You just need to read the response from the xml – Atul Goyal Aug 31 '12 at 09:04
  • No Atul Goyal...If we make a connection using HTTP it will return code (consider if 400--connected,404 means server not found) like that.. – prakash .k Aug 31 '12 at 09:23

1 Answers1

0

You are reading response code, you need to read response from the HTTPConnection, try this:

InputStream response = conn.getInputStream();

and then read the data (response) from this InputStream.

Check out this mini tutorial on SO.

Community
  • 1
  • 1
Atul Goyal
  • 3,371
  • 4
  • 37
  • 55