Merge branch 'master' of http://bdgit.educoder.net/p01643725/paz2s9bc5
commit
738fadda58
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".SearchContentActivity">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/search_content"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -0,0 +1,72 @@
|
|||||||
|
package com.example.cmknowledgegraph;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
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.ProtocolException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class getTest {
|
||||||
|
|
||||||
|
public static String executeSearchGet(){
|
||||||
|
HttpURLConnection connection = null;
|
||||||
|
InputStream in = null;
|
||||||
|
String name="头痛";
|
||||||
|
String address="/rest/cmkg/question/hello";
|
||||||
|
|
||||||
|
String Url = "http://10.0.2.2:8080"+address;
|
||||||
|
String path = Url + "?name="+name;
|
||||||
|
URL url = null;
|
||||||
|
try {
|
||||||
|
url = new URL(path);
|
||||||
|
connection = (HttpURLConnection)url.openConnection();
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
connection.setConnectTimeout(100000);//建立连接超时
|
||||||
|
connection.setReadTimeout(80000);//传输数据超时
|
||||||
|
in = connection.getInputStream();
|
||||||
|
|
||||||
|
BufferedReader reader = null;//输入流
|
||||||
|
String line = "";//读取返回的每一行
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
try {
|
||||||
|
reader = new BufferedReader(new InputStreamReader(in));
|
||||||
|
while((line = reader.readLine()) != null) {
|
||||||
|
response.append(line);
|
||||||
|
}
|
||||||
|
//这时候response就是一个连续字符串了吧
|
||||||
|
Log.i("response+++++",response+"返回值");
|
||||||
|
System.out.println(response.toString());
|
||||||
|
// return response.toString();
|
||||||
|
//
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}finally {
|
||||||
|
if(reader!=null){
|
||||||
|
try {
|
||||||
|
reader.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ProtocolException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String args[]){
|
||||||
|
executeSearchGet();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue