httpclient を使用して、次のようにプロジェクトにログインします。
public void login(String username,String password){
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://localhost:8080/j_spring_security_check");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("j_username", username));
nameValuePairs.add(new BasicNameValuePair("j_password", password));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
} catch (IOException e) {
e.printStackTrace();
}
}
そして、私は次のように上記を使用します:
HttpClientRequests httpRequest = new HttpClientRequests();
httpRequest.login("mayank","hexgen");
今、私POST
は次のようなメソッドのリクエストを送信したいと思います:
@RequestMapping(method = RequestMethod.POST, value = "/trade/createrequisition")
public @ResponseBody
void createRequisition(@RequestBody CreateRequisitionRO[] request,
@RequestHeader("validateOnly") boolean validateOnly) {
....
}
だから私は次のようなリフレクションを作成しました:
HttpClientRequests httpRequest = new HttpClientRequests();
Class[] paramString = new Class[1];
paramString[0] = String.class;
Class parames = CreateRequisitionRO[].class;
CreateRequisitionRO[] roRqequest = new CreateRequisitionRO[1];
boolean istrueOrFalse=true;
Class booleanVal ;
booleanVal = Boolean.TYPE;
Class cls;
try {
cls = Class.forName("com.hexgen.api.facade.HexgenWebAPI");
Method method = cls.getDeclaredMethod("createRequisition", parames,booleanVal);
RequestMapping methodRequestMappingAnnotation = method.getAnnotation(RequestMapping.class);
RequestMethod[] methods = methodRequestMappingAnnotation.method();
String[] mappingValues = methodRequestMappingAnnotation.value();
//String methodType = methods[0].name();
//String url = mappingValues[0];
httpRequest.login("mayank","hexgen");
}catch(Exception ex){
ex.printStackTrace();
}
この後httpRequest.login("mayank","hexgen");
、次のメソッドにアクセスするためのリクエストを送信する方法:
@RequestMapping(method = RequestMethod.POST, value = "/trade/createrequisition")
public @ResponseBody
void createRequisition(@RequestBody CreateRequisitionRO[] request,
@RequestHeader("validateOnly") boolean validateOnly) {
....
}
そう。
プログラムでシステムにログインできますが、ログインに成功した後に呼び出すことができません。
これを解決するのを手伝ってください。