Created
December 4, 2012 16:10
-
-
Save henryyan/4205625 to your computer and use it in GitHub Desktop.
使用HttpClient登陆Activiti Rest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.BufferedReader; | |
| import java.io.IOException; | |
| import java.io.InputStreamReader; | |
| import org.apache.http.HttpResponse; | |
| import org.apache.http.client.methods.HttpPost; | |
| import org.apache.http.entity.StringEntity; | |
| import org.apache.http.impl.client.DefaultHttpClient; | |
| public class TestLogin { | |
| public static void main(String[] args) throws Exception, IOException { | |
| DefaultHttpClient httpClient = new DefaultHttpClient(); | |
| HttpPost postRequest = new HttpPost("http://localhost:8080/activiti-rest/service/login"); | |
| StringEntity input = new StringEntity("{\"userId\":\"kermit\",\"password\":\"kermit\"}"); | |
| input.setContentType("application/json"); | |
| postRequest.setEntity(input); | |
| HttpResponse response = httpClient.execute(postRequest); | |
| BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); | |
| String output; | |
| System.out.println("Output from Server .... \n"); | |
| while ((output = br.readLine()) != null) { | |
| System.out.println(output); | |
| } | |
| httpClient.getConnectionManager().shutdown(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
O(∩_∩)O谢谢兔子的这段代码