Skip to content

Instantly share code, notes, and snippets.

@henryyan
Created December 4, 2012 16:10
Show Gist options
  • Select an option

  • Save henryyan/4205625 to your computer and use it in GitHub Desktop.

Select an option

Save henryyan/4205625 to your computer and use it in GitHub Desktop.
使用HttpClient登陆Activiti Rest
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();
}
}
@geosmart
Copy link
Copy Markdown

geosmart commented Jan 4, 2013

O(∩_∩)O谢谢兔子的这段代码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment