连网(网站上传账户和密码)

连网的工具类

public class POST {

private static String s;
private static String explain;

public static String getIntent(String web){
    try {
        URL url=new URL(web);
        Log.e("s","s");
        HttpURLConnection connection= (HttpURLConnection) url.openConnection();
        connection.setConnectTimeout(3000);
        connection.setRequestMethod("GET");
        connection.setRequestProperty("accept","*/*");
        connection.setRequestProperty("connection","Keep-Alive");
        connection.setRequestProperty("Aaccept-Charset","utf-8");
        int code = connection.getResponseCode();
        if (code==200){
            BufferedReader output=new BufferedReader(new InputStreamReader
                    (connection.getInputStream(),"UTF-8"));
            s = output.readLine();
            JSONObject json=new JSONObject(s);
            JSONObject sub=json.getJSONObject("data");
            String message=json.getString("message");
            explain = sub.getString("explain");
            Log.e("sss","explain="+explain);

        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return explain;
}
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容