android.os.NetworkOnMainThreadException :
The exception that is thrown when an application attempts to perform a networking operation on its main thread.
use AsyncTask for making network related task from Ui Thread
or you are using API LEVEL 9 then just set StrictMode for Current Activity in onCreate()
method before making network request :
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectNetwork() // or .detectAll() for all detectable problems
.penaltyDialog() //show a dialog
//.permitNetwork() //permit Network access
.build());