android - How to download html source using RoboSpice? -


i want download html static blog page can relevant data , use it. asynchronous procedures i'm using robospice library.

thing is, using simpletextrequest first line of html, namely

<?xml version="1.0" encoding="utf-8"?> 

which request should use download whole html source? i've failed find similar in samples. , googling "robospice" leads sourcecode, seems there's little in terms of tutorials library.

update: inspiredby first answer, have created custom spicerequest:

 public class htmlrequest extends spicerequest<string> {      private static string requrl;      public htmlrequest(string url) {         super(string.class);         requrl = url;         alog.d("htmlrequest.htmlrequest url : " + url);     }      @override     public string loaddatafromnetwork() throws exception {         string html = "";          httpclient httpclient = new defaulthttpclient();         stringbuilder builder = new stringbuilder();         httpget = new httpget(requrl);         httpresponse response = httpclient.execute(get);         statusline statusline = response.getstatusline();         int statuscode = statusline.getstatuscode();         alog.d("htmlrequest.loaddatafromnetwork statuscode : " + statuscode);         if (statuscode == 200) {             /*              * si todo fue ok, montamos la string con el html              */             httpentity entity = response.getentity();             inputstream content = entity.getcontent();             bufferedreader reader = new bufferedreader(new inputstreamreader(content));             string line;             while ((line = reader.readline()) != null) {                 alog.d("htmlrequest.loaddatafromnetwork line : " + line);                 builder.append(line);             }             html = builder.tostring();             alog.d("htmlrequest.loaddatafromnetwork html : " + html);         }          httpclient.getconnectionmanager().shutdown();         return html;     }  } 

then, on activity have

spicemanager.execute(htmlrequest, "text", durationinmillis.never, new staticitemrequestlistener()); 

and yet none of logs set on custom request, besides 1 in constructor method.

thing is: while htmlrequest apparently isn't being executed, still xml header above. must doing wrong , yet unable see it...

it's strange getting header of xml file instead html. try asking server html version:

public class examplerequest extends spicerequest<string> {      public examplerequest() {         super(string.class);     }      @override     public string loaddatafromnetwork() throws exception {          string url = "your website url";          if (build.version.sdk_int < build.version_codes.froyo) {             system.setproperty("http.keepalive", "false");         }          httpurlconnection urlconnection = (httpurlconnection) new url(url)             .openconnection();         urlconnection.setrequestproperty("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");                urlconnection.setrequestproperty("content-type", "text/html");                     string result = ioutils.tostring(urlconnection.getinputstream());         urlconnection.disconnect();          return result;     } } 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -