import android.util.Log;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
/**
* Created by Lenovo on 2018/5/24.
*/
public class GetUtils {
public static String LOGIN_URL = "http://192.168.202.107:19433/api/WebApi/PdaLogin?";
public static String LoginByGet(String name, String passwd) {
String msg = "";
try {
String data = "account=" + URLEncoder.encode(name, "UTF-8") +
"&password=" + URLEncoder.encode(passwd, "UTF-8");
URL url=new URL( LOGIN_URL + data);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
conn.setReadTimeout(5000);
conn.setConnectTimeout(5000);
conn.connect();
InputStream inputStream=null;
BufferedReader reader=null;
if(conn.getResponseCode()==HttpURLConnection.HTTP_OK){
inputStream=conn.getInputStream();
reader=new BufferedReader(new InputStreamReader(inputStream));
String result = reader.readLine();
JSONObject json_test = new JSONObject(result);
Log.e("json", json_test.get("Data").toString());
Log.e("json", json_test.get("Status").toString());
Log.e("json", json_test.get("Info").toString());
}
reader.close();
inputStream.close();
conn.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
return msg;
}
}