android.os.NetworkOnMainThreadException

This exception occurs when you write network code on main thread (UI thread). It will throw following exception

android.os.NetworkOnMainThreadException

Solution:-

Write your network part code on background threat (AsyncTask)

 

For more detail check following links:

How to use background thread in android. Android thread example

How to use AsyncTask in android.