问一个关于android发出post请求的有关问题

问一个关于android发出post请求的问题
具体问题是这样的,我写了一个发送post的类,单独运行里面的main函数是可以的,请求正常。
但是我在我的mainactivity里面使用的时候却不能请求。
android的项目已经允许了INTERNET的权限。

发送post类的代码是:
package com.yuanzifu.helloworld;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

public class HttpUtils
{

    // 请求服务器端的url
    //private static String PATH = "https://w.seu.edu.cn/portal/login.php";
    private static String PATH = "http://www.seu.edu.cn";
    private static URL url;

    public HttpUtils()
    {
        // TODO Auto-generated constructor stub
    }

    static
    {
        try
        {
            url = new URL(PATH);
        } catch (MalformedURLException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    /**
     * @param params
     *            填写的url的参数
     * @param encode
     *            字节编码
     * @return
     */
    public static String sendPostMessage(Map<String, String> params, String encode)
    {
        System.setProperty("jsse.enableSNIExtension", "false");
        // 作为StringBuffer初始化的字符串
        StringBuffer buffer = new StringBuffer();
        try
        {
            if (params != null && !params.isEmpty())
            {
                for (Map.Entry<String, String> entry : params.entrySet())
                {
                    // 完成转码操作
                    buffer.append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue(), encode)).append("&");
                }
                buffer.deleteCharAt(buffer.length() - 1);
            }
            // System.out.println(buffer.toString());
            // 删除掉最有一个&

            //System.out.println("-->>" + buffer.toString());
            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setConnectTimeout(30000);
            urlConnection.setRequestMethod("POST");
            urlConnection.setDoInput(true);// 表示从服务器获取数据
            urlConnection.setDoOutput(true);// 表示向服务器写数据
            // 获得上传信息的字节大小以及长度
            byte[] mydata = buffer.toString().getBytes();
            // 表示设置请求体的类型是文本类型
            urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            urlConnection.setRequestProperty("Content-Length", String.valueOf(mydata.length));
            // 获得输出流,向服务器输出数据
            OutputStream outputStream = urlConnection.getOutputStream();
            outputStream.write(mydata, 0, mydata.length);
            outputStream.close();
            // 获得服务器响应的结果和状态码
            int responseCode = urlConnection.getResponseCode();
            if (responseCode == 200)
            {
                return changeInputStream(urlConnection.getInputStream(), encode);
            }
        } catch (UnsupportedEncodingException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 将一个输入流转换成指定编码的字符串
     *
     * @param inputStream
     * @param encode
     * @return
     */
    private static String changeInputStream(InputStream inputStream, String encode)
    {
        // TODO Auto-generated method stub
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        byte[] data = new byte[1024];
        int len = 0;
        String result = "";
        if (inputStream != null)
        {
            try
            {
                while ((len = inputStream.read(data)) != -1)
                {
                    outputStream.write(data, 0, len);
                }
                result = new String(outputStream.toByteArray(), encode);
            } catch (IOException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return result;
    }

    public static void main(String[] a)
    {
        // TODO Auto-generated method stub
        Map<String, String> params = new HashMap<String, String>();
        params.put("username", "220131440");
        params.put("password", "574423");
        System.out.println("System-"+params.toString());
        String result = HttpUtils.sendPostMessage(params, "utf-8");
        System.out.println("--System->>" + result);
    }

}


我在mainactivity里面有一个按钮的监听器,如下:
/*set login button click listener*/
        login_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                /*get name and password*/
                String login_name = name_edittext.getText().toString();
                String login_password = passwort_edittext.getText().toString();
                //Toast.makeText(getApplicationContext(), login_name+"-"+login_password, Toast.LENGTH_LONG).show();

                /*sent post to server*/
                Map<String, String> params = new HashMap<String, String>();
                params.put("username", "220131440");
                params.put("password", "574423");
                String result = HttpUtils.sendPostMessage(params, "utf-8");
                System.out.println("System-test");
                System.out.println("System-" + result);
                HttpUtils.main(null);

                show_textvied.setText(result);

                showImage();


            }
        });


我感觉这样不能请求不科学啊,请大神解答。
------解决思路----------------------
对Internet的操作不是要在另一个thread里面运行吗?在主GUI线程中应该会抛异常吧。
------解决思路----------------------
还是访问网络的操作不能放在主线程
------解决思路----------------------
重新开一个线程把访问网络的写进去就行了,我以前也遇到过!
------解决思路----------------------
要使用新线程,不要在GUI线程中运行~