/** Test that the body can be set as a array of parameters */
 public void testParametersBodyToParamServlet() throws Exception {
   PostMethod method = new PostMethod("/");
   NameValuePair[] parametersBody =
       new NameValuePair[] {
         new NameValuePair("pname1", "pvalue1"), new NameValuePair("pname2", "pvalue2")
       };
   method.setRequestBody(parametersBody);
   this.server.setHttpService(new EchoService());
   try {
     this.client.executeMethod(method);
     assertEquals(200, method.getStatusCode());
     String body = method.getResponseBodyAsString();
     assertEquals("pname1=pvalue1&pname2=pvalue2", body);
   } finally {
     method.releaseConnection();
   }
 }
Пример #2
0
 /**
  * Test that {@link PostMethod#addParameter(java.lang.String,java.lang.String)} and {@link
  * PostMethod#setQueryString(java.lang.String)} combine properly.
  */
 public void testPostMethodParameterAndQueryString() throws Exception {
   this.server.setHttpService(new QueryInfoService());
   PostMethod method = new PostMethod("/");
   method.setQueryString("query=string");
   method.setRequestBody(
       new NameValuePair[] {
         new NameValuePair("param", "eter"), new NameValuePair("para", "meter")
       });
   try {
     this.client.executeMethod(method);
     assertEquals(200, method.getStatusCode());
     String response = method.getResponseBodyAsString();
     assertTrue(response.indexOf("QueryString=\"query=string\"") >= 0);
     assertFalse(response.indexOf("QueryString=\"param=eter&para=meter\"") >= 0);
   } finally {
     method.releaseConnection();
   }
 }