You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.6 KiB
88 lines
2.6 KiB
package com.example.PersonalCenter;
|
|
|
|
import android.util.Log;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.example.tools.retuData;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStreamReader;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.MalformedURLException;
|
|
import java.net.URL;
|
|
|
|
|
|
|
|
public class WebServiceGet {
|
|
public static String UrlPath = "http://114.55.37.70/CMKnowledgeGraph";//服务器项目的总请求路径
|
|
//登录请求
|
|
public static String executeHttpGet(String phonenumber,String password,String address) {
|
|
HttpURLConnection connection = null;
|
|
InputStream br = null;
|
|
|
|
String Url = UrlPath + address;
|
|
String path = Url+"?phonenumber=" + phonenumber + "&password=" + password;
|
|
Log.i("login---====--",""+path);
|
|
URL url = null;
|
|
try {
|
|
url = new URL(path);
|
|
|
|
connection = (HttpURLConnection) url.openConnection();
|
|
connection.setConnectTimeout(100000);
|
|
connection.setReadTimeout(80000);
|
|
connection.setRequestMethod("GET");
|
|
//获取结果
|
|
// int responseCode = connection.getResponseCode();
|
|
// if(responseCode == 200){
|
|
br = connection.getInputStream();
|
|
String readline = parseInfo(br);
|
|
|
|
return readline;
|
|
|
|
// }
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}finally {
|
|
if(connection!=null){
|
|
connection.disconnect();
|
|
|
|
}
|
|
if(br!=null){
|
|
try {
|
|
br.close();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
//将字节流转换成String
|
|
public static String parseInfo(InputStream inputStream){
|
|
BufferedReader reader = null;
|
|
String line = "";
|
|
StringBuilder response = new StringBuilder();
|
|
try {
|
|
reader = new BufferedReader(new InputStreamReader(inputStream));
|
|
while((line = reader.readLine()) != null) {
|
|
response.append(line);
|
|
}
|
|
return response.toString();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}finally {
|
|
if(reader!=null){
|
|
try {
|
|
reader.close();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|