L
Lucius1972
Neues Mitglied
- 0
Hallo Leute,
Ich moechte mich gerne an der Webseite von meinen Handy provider Inloggen MijnKPN - beheer uw KPN diensten einloggen, um danach auslesen zu koennen was mein Restgutenhaben meines Bundles ist.
Dies soll in meiner App angegeben werden.
Problem ist dass diese Seite kein php benutzt aber eine xml code, wenn Ich das gut gesehen habe.
Auch nutzt Sie "https" https://access.kpn.com/CAUT/AuthenticationServlet
Jetzt habe Ich schon folgende Codes gefunden wovan Ich nicht weiss ob diese zu gebrauchen sind fuer mein Vorhaben.
Set up an HTTP/HTTPS client:
POST method and retrieve the body of the HttpResponse using:
Dass ganze wird dan mittels Parser ausgelesen:
Koennte mir bitte Jemand hier helfen und einen Weg zeigen wie Ich dies in meiner App verarbeiten kann?
Wenn Ich es schon hinkriegen koennte mich ueber meiner App einzuloggen, waere schon Klasse.
PS: Ich benutze Eclipse Indigo..
Vielen Dank im voraus.
Gruss,
Lucius
Ich moechte mich gerne an der Webseite von meinen Handy provider Inloggen MijnKPN - beheer uw KPN diensten einloggen, um danach auslesen zu koennen was mein Restgutenhaben meines Bundles ist.
Dies soll in meiner App angegeben werden.
Problem ist dass diese Seite kein php benutzt aber eine xml code, wenn Ich das gut gesehen habe.
Auch nutzt Sie "https" https://access.kpn.com/CAUT/AuthenticationServlet
Jetzt habe Ich schon folgende Codes gefunden wovan Ich nicht weiss ob diese zu gebrauchen sind fuer mein Vorhaben.
Set up an HTTP/HTTPS client:
Code:
public DefaultHttpClient getClient() {
DefaultHttpClient ret = null;
//sets up parameters
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "utf-8");
params.setBooleanParameter("http.protocol.expect-continue", false);
//registers schemes for both http and https
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
sslSocketFactory.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
registry.register(new Scheme("https", sslSocketFactory, 443));
ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry);
ret = new DefaultHttpClient(manager, params);
return ret;
}
POST method and retrieve the body of the HttpResponse using:
Code:
public static String getResponseBody(HttpResponse response) {
String response_text = null;
HttpEntity entity = null;
try {
entity = response.getEntity();
response_text = _getResponseBody(entity);
} catch (ParseException e) {
e.printStackTrace();
} catch (IOException e) {
if (entity != null) {
try {
entity.consumeContent();
} catch (IOException e1) {
}
}
}
return response_text;
}
Dass ganze wird dan mittels Parser ausgelesen:
Code:
public class OptionScraper {
// example XPATH queries in the form of strings - will be used later
private static final String NAME_XPATH = "//div[@class='yfi_quote']/div[@class='hd']/h2";
private static final String TIME_XPATH = "//table[@id='time_table']/tbody/tr/td[@class='yfnc_tabledata1']";
private static final String PRICE_XPATH = "//table[@id='price_table']//tr//span";
// TagNode object, its use will come in later
private static TagNode node;
// a method that helps me retrieve the stock option's data based off the name (i.e. GOUAA is one of Google's stock options)
public static Option getOptionFromName(String name) throws XPatherException, ParserConfigurationException,SAXException, IOException, XPatherException {
// the URL whose HTML I want to retrieve and parse
String option_url = "http://finance.yahoo.com/q?s=" + name.toUpperCase();
// this is where the HtmlCleaner comes in, I initialize it here
HtmlCleaner cleaner = new HtmlCleaner();
CleanerProperties props = cleaner.getProperties();
props.setAllowHtmlInsideAttributes(true);
props.setAllowMultiWordAttributes(true);
props.setRecognizeUnicodeChars(true);
props.setOmitComments(true);
// open a connection to the desired URL
URL url = new URL(option_url);
URLConnection conn = url.openConnection();
//use the cleaner to "clean" the HTML and return it as a TagNode object
node = cleaner.clean(new InputStreamReader(conn.getInputStream()));
// once the HTML is cleaned, then you can run your XPATH expressions on the node, which will then return an array of TagNode objects (these are returned as Objects but get casted below)
Object[] info_nodes = node.evaluateXPath(NAME_XPATH);
Object[] time_nodes = node.evaluateXPath(TIME_XPATH);
Object[] price_nodes = node.evaluateXPath(PRICE_XPATH);
// here I just do a simple check to make sure that my XPATH was correct and that an actual node(s) was returned
if (info_nodes.length > 0) {
// casted to a TagNode
TagNode info_node = (TagNode) info_nodes[0];
// how to retrieve the contents as a string
String info = info_node.getChildren().iterator().next().toString().trim();
// some method that processes the string of information (in my case, this was the stock quote, etc)
processInfoNode(o, info);
}
if (time_nodes.length > 0) {
TagNode time_node = (TagNode) time_nodes[0];
String date = time_node.getChildren().iterator().next().toString().trim();
// date returned in 15-Jan-10 format, so this is some method I wrote to just parse that string into the format that I use
processDateNode(o, date);
}
if (price_nodes.length > 0) {
TagNode price_node = (TagNode) price_nodes[0];
double price = Double.parseDouble(price_node.getChildren().iterator().next().toString().trim());
o.setPremium(price);
}
return o;
}
}
Wenn Ich es schon hinkriegen koennte mich ueber meiner App einzuloggen, waere schon Klasse.
PS: Ich benutze Eclipse Indigo..
Vielen Dank im voraus.
Gruss,
Lucius