android端请求代码
public void buttonhttpclient(){
new Thread(new Runnable(){
public void run(){
String estring=null;
HttpClient hc=new DefaultHttpClient();
HttpGet hg=new HttpGet("http://127.0.0.1:8080/");
try {
在代码运行到这里阻塞
HttpResponse httpResponse=hc.execute(hg);
System.out.println("-----------doPost--------------状态码"+httpResponse.getStatusLine().getStatusCode());
if(httpResponse.getStatusLine().getStatusCode()==200){
HttpEntity entity=httpResponse.getEntity();
estring=EntityUtils.toString(entity,"utf-8");
System.out.println("-----------doPost"+estring);
}
Message msg=new Message();
msg.what=CS;
msg.obj=estring;
handler.sendMessage(msg);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
}
spring boot代码
@RestController
@SpringBootApplication
//@ServletComponentScan
public class Demo1Application {
@RequestMapping("/")
@ResponseBody
String index() {
System.out.println("-----------doPost----------------");
return "hello";
}
public static void main(String[] args) {
SpringApplication.run(Demo1Application.class, args);
//new first();
}
}
public void buttonhttpclient(){
new Thread(new Runnable(){
public void run(){
String estring=null;
HttpClient hc=new DefaultHttpClient();
HttpGet hg=new HttpGet("http://127.0.0.1:8080/");
try {
在代码运行到这里阻塞
HttpResponse httpResponse=hc.execute(hg);
System.out.println("-----------doPost--------------状态码"+httpResponse.getStatusLine().getStatusCode());
if(httpResponse.getStatusLine().getStatusCode()==200){
HttpEntity entity=httpResponse.getEntity();
estring=EntityUtils.toString(entity,"utf-8");
System.out.println("-----------doPost"+estring);
}
Message msg=new Message();
msg.what=CS;
msg.obj=estring;
handler.sendMessage(msg);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
}
spring boot代码
@RestController
@SpringBootApplication
//@ServletComponentScan
public class Demo1Application {
@RequestMapping("/")
@ResponseBody
String index() {
System.out.println("-----------doPost----------------");
return "hello";
}
public static void main(String[] args) {
SpringApplication.run(Demo1Application.class, args);
//new first();
}
}