Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Http get request in Android

I need help with sending http get request. Like this:

URL connectURL;
connectURL = new URL(address);
HttpURLConnection conn = (HttpURLConnection)connectURL.openConnection(); 
// do some setup
conn.setDoInput(true); 
conn.setDoOutput(true); 
conn.setUseCaches(false); 
conn.setRequestMethod("GET"); 
// connect and flush the request out
conn.connect();
conn.getOutputStream().flush();
// now fetch the results
String response = getResponse(conn);
et.setText(response);

I searched the web but any method I try, the code fails at 'conn.connect();'. Any clues?

like image 975
user568021 Avatar asked Jul 26 '26 14:07

user568021


1 Answers

Very hard to tell without the actual error message. Random thought: did you add the internet permission to you manifest?

 <uses-permission android:name="android.permission.INTERNET"/> 
like image 193
Nanne Avatar answered Jul 29 '26 06:07

Nanne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!