連網(網站上傳賬戶和密碼)

連網的工具類

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;
}
}
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容