Skip to content

Instantly share code, notes, and snippets.

@geosmart
Forked from henryyan/gist:4205625
Created January 5, 2013 01:18
Show Gist options
  • Save geosmart/4459037 to your computer and use it in GitHub Desktop.
Save geosmart/4459037 to your computer and use it in GitHub Desktop.
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
Author

geosmart commented Jan 5, 2013

客户端调用restlet

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