idea 修改源

国内访问Maven仓库非常慢,笔者今天忘记切换国内源更新Maven仓库竟然更新了一下午。如果改成国内的源,那么很快就更新完成了。
在IDEA中打开“Settings”(快捷键Ctrl+Alt+S);
在搜索框中输入“maven”,找到Maven设置菜单,点击进去,在红框所示路径新建“settings.xml”文件,并写入如下内容,勾选“”override,如下图所示:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <mirrors>
        <!-- 阿里云仓库 -->
        <mirror>
            <id>alimaven</id>
            <mirrorOf>central</mirrorOf>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
        </mirror>


        <!-- 中央仓库1 -->
        <mirror>
            <id>repo1</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://repo1.maven.org/maven2/</url>
        </mirror>


        <!-- 中央仓库2 -->
        <mirror>
            <id>repo2</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://repo2.maven.org/maven2/</url>
        </mirror>
    </mirrors> 

</settings>

android post/get 请求

public class LoginServer {
/**
*get的方式请求
*@param username 用户名
*@param password 密码
*@return 返回null 登录异常
/ public static String loginByGet(String username,String password){ //get的方式提交就是url拼接的方式 String path = “http://172.16.168.111:1010/login.php?username=”+username+”&password=”+password; try { URL url = new URL(path); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setConnectTimeout(5000); connection.setRequestMethod(“GET”); //获得结果码 int responseCode = connection.getResponseCode(); if(responseCode ==200){ //请求成功 获得返回的流 InputStream is = connection.getInputStream(); return IOSUtil.inputStream2String(is); }else { //请求失败 return null; } } catch (MalformedURLException e) { e.printStackTrace(); } catch (ProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } /* * post的方式请求
*@param username 用户名
*@param password 密码
*@return 返回null 登录异常
*/
public static String loginByPost(String username,String password){
String path = “http://172.16.168.111:1010/login.php”;
try {
URL url = new URL(path);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(5000);
connection.setRequestMethod(“POST”);

        //数据准备
        String data = "username="+username+"&password="+password;
        //至少要设置的两个请求头
        connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
        connection.setRequestProperty("Content-Length", data.length()+"");

        //post的方式提交实际上是留的方式提交给服务器
        connection.setDoOutput(true);
        OutputStream outputStream = connection.getOutputStream();
        outputStream.write(data.getBytes());

        //获得结果码
        int responseCode = connection.getResponseCode();
        if(responseCode ==200){
            //请求成功
            InputStream is = connection.getInputStream();
            return IOSUtil.inputStream2String(is);
        }else {
            //请求失败
            return null;
        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (ProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}