Reputation: 51
im not experienced in java and i got a working example code for some XML interaction, my only problem is that i need to POST data (username/password)
the relevant code is:
static String myUrlString = "http://www.grupoandroid.com/interface/mobile/index.php";
protected TheParser(){
try {
this.myUrl = new URL(myUrlString);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
protected InputStream getInputStream() {
try {
return myUrl.openConnection().getInputStream();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Upvotes: 0
Views: 1051
Reputation: 11
I think you're better off using an http-client library, rather than parsing the full http stack yourself.
You can find enough examples and tutorials in the web for these.
Upvotes: 0
Reputation: 48176
you can use HttpURLConnection
protected InputStream getInputStream() {
try {
HttpURLConnection con = new HttpURLConnection(myUrl);
con.setRequestMethod("POST");
//writeout data to the output stream
return con.getInputStream();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Upvotes: 1