Connect to "non-mobile" version of websites,

Put your problem here if it does not fit any of the other categories.

Connect to "non-mobile" version of websites,

Postby nioupy » Mon May 24, 2010 11:36 am

Hi,
I am not sure of how to formulate my searches on that problem, and so i don't find what i am looking for... If someone can give me a hint, I'll appreciate :)

I am doing a rss reader that gets data from the feed and then from the links for each article. The problem is that when fetching the webpage with the full article, I don't get the data I expected... It took me a while to understand why and then I saw it : I am fetching a mobile-friendly version of my page, and it doesn't contain what I need.

Is there a way to make sure my android device is getting the full version of the webpage ?

Thanks in advance,

nicolas
nioupy
Developer
Developer
 
Posts: 36
Joined: Sat Apr 03, 2010 1:34 pm

Top

Re: Connect to "non-mobile" version of websites,

Postby nioupy » Sat Jun 05, 2010 6:28 pm

In case someone ever has the same question, here is how i solved the problem :

Code: Select all

private static final String user_agent_id = "Mozilla/4.0";

        String uriAPI = myLink;
        /* Establish HTTP Get object  */
        HttpGet httpRequest = new HttpGet(uriAPI);
        httpRequest.addHeader("user-agent-id",this.user_agent_id);

      try
        {
          /* Send a request and waits for the response  */
          HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);
          /* If the status code is 200 ok  */
          if(httpResponse.getStatusLine().getStatusCode() == 200) 
          {
            /* Read  */
            String strResult = EntityUtils.toString(httpResponse.getEntity());
          return strResult;
          }
          else
          {
            return "Error Response: "+httpResponse.getStatusLine().toString();
          }
        }
        catch (ClientProtocolException e)
        { 
          e.printStackTrace();
          return e.getMessage().toString();
        }
        catch (IOException e)
        { 
          e.printStackTrace();
          return e.getMessage().toString();
        }
        catch (Exception e)
        { 
          e.printStackTrace();
          return e.getMessage().toString();   
        }


things got much faster once i understood what i was looking for was the UserAgent ID
nioupy
Developer
Developer
 
Posts: 36
Joined: Sat Apr 03, 2010 1:34 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 15 guests