Package org.apache.commons.httpclient.methods

Examples of org.apache.commons.httpclient.methods.PostMethod


    java.net.URL u=new java.net.URL(url);
    String soapAction="";
    String request=new String(b);
       
    HttpClient httpClient = new HttpClient();
        PostMethod httpPostMethod = new PostMethod(u.toExternalForm());
        httpPostMethod.setRequestHeader("SOAPAction", "\"" + soapAction + "\"");
        httpPostMethod.setRequestHeader("Content-Type", "text/xml");
        httpPostMethod.setRequestEntity(new StringRequestEntity(request));
        httpClient.executeMethod(httpPostMethod);
        String result=httpPostMethod.getResponseBodyAsString();
   
    return(result);
  }
View Full Code Here


       StringBuffer sb = new StringBuffer();

       if ("GET".equalsIgnoreCase(method)) {
           theMethod = new GetMethod(urlpath);
       } else if ("POST".equalsIgnoreCase(method)) {
           theMethod = new PostMethod(urlpath);
       }

       if (username != null && password != null) {

           try {
               httpclient.executeMethod(theMethod);
           } catch (IOException e) {
               e.printStackTrace();
           } finally {
               theMethod.releaseConnection();
           }
         PostMethod authMethod = new PostMethod(authentication_url);
         NameValuePair[] data = {new NameValuePair("j_username", username), new NameValuePair("j_password", password)};
         authMethod.setRequestBody(data);
           try {
               httpclient.executeMethod(authMethod);
           } catch (IOException e) {
               e.printStackTrace();
           } finally {
               authMethod.releaseConnection();
           }
       }

       try {
         httpclient.executeMethod(theMethod);
View Full Code Here

        .get(ModelMap.RPC_ARGS_KEY) : null;

    if (methodType.equalsIgnoreCase("get")) {
      method = new GetMethod(url);
    } else if (methodType.equalsIgnoreCase("post")) {
      PostMethod postMethod = new PostMethod(url);
      if (args != null) {
        byte[] output = constructArgs(method, args);
        postMethod.setRequestEntity(new ByteArrayRequestEntity(output));
      }
      method = postMethod;
    } else if (methodType.equalsIgnoreCase("put")) {
      method = new PutMethod(url);
      if (args != null) {
View Full Code Here

  public synchronized  void login(HttpClient httpClient,
      String securityHost, String loginUrl,String userName,String password) throws Exception {
    Exception exception = null;

    GetMethod authget = null;
    PostMethod authpost = null;
    GetMethod redirect = null;
    try {
      httpClient.getParams().setCookiePolicy(
          CookiePolicy.BROWSER_COMPATIBILITY);

      authget = new GetMethod(securityHost + loginUrl);

      httpClient.executeMethod(authget);
      int statuscode = authget.getStatusCode();

      authpost = new PostMethod(securityHost + "/j_security_check");
      NameValuePair j_username = new NameValuePair("j_username", userName);
      NameValuePair j_password = new NameValuePair("j_password", password);
      authpost.setRequestBody(new NameValuePair[] { j_username, j_password });

      httpClient.executeMethod(authpost);
      statuscode = authpost.getStatusCode();
      if ((statuscode == HttpStatus.SC_MOVED_TEMPORARILY)
          || (statuscode == HttpStatus.SC_MOVED_PERMANENTLY)
          || (statuscode == HttpStatus.SC_SEE_OTHER)
          || (statuscode == HttpStatus.SC_TEMPORARY_REDIRECT)) {
        Header header = authpost.getResponseHeader("location");
        if (header != null) {
          String newuri = header.getValue();
          if ((newuri == null) || (newuri.equals(""))) {
            newuri = "/";
          }
          redirect = new GetMethod(newuri);

          httpClient.executeMethod(redirect);
          redirect.releaseConnection();
        }
      } else {
        exception = new LoginErrorException("用户名或者密码错误");
      }
    } catch (Exception e) {
      exception = e;
    } finally {
      if (authget != null)
        authget.releaseConnection();
      if (authpost != null)
        authpost.releaseConnection();
      if (redirect != null)
        redirect.releaseConnection();
    }

    if (exception != null)
View Full Code Here


        HttpClient httpClient = new HttpClient();
        httpClient.getParams().setParameter("http.protocol.expect-continue", true);

        PostMethod meth = new PostMethod("http://localhost:" + server.getLocalPort() + "/test");
        meth.setRequestBody("OK");

        httpClient.executeMethod(meth);
       
        Assert.assertEquals(200, meth.getStatusCode());
        Assert.assertEquals("OK", meth.getResponseBodyAsString());
       
        meth.releaseConnection();
       
        server.close();
    }
View Full Code Here

   * @see net.sf.xbus.technical.ObjectSender#execute(java.lang.String,
   *      java.lang.Object)
   */
  public Object execute(String function, Object callData) throws XException
  {
    PostMethod method = initialize(function, null);

    InputStream inStream = (InputStream) callData;
    method.setRequestEntity(new InputStreamRequestEntity(inStream));
    sendMessage(method);

    try
    {
      inStream.close();
View Full Code Here

   *
   * @return <code>null</code>
   */
  public String execute(String function, String callData) throws XException
  {
    PostMethod method = initialize(function, null);

    if (callData == null)
      callData = "";

    method.setRequestEntity(new StringRequestEntity(callData));
    // method.setRequestContentLength(callData.length());
    // method.setRequestBody(callData);

    return sendMessage(method);
  }
View Full Code Here

    {
      Protocol.registerProtocol("https", new Protocol("https",
          new EasySSLProtocolSocketFactory(), 8443));
    }

    PostMethod method = new PostMethod(url);

    setRequestHeaders(function, method);

    return method;
  }
View Full Code Here

    }
    Node rootNode = nodes.item(0);

    String url = XMLHelper.getAttribute(rootNode, "url");

    PostMethod method = initialize(function, url);

    nodes = rootNode.getChildNodes();
    String name = null;
    String value = null;
    Vector params = new Vector();
    for (int i = 0; i < nodes.getLength(); i++)
    {
      name = nodes.item(i).getNodeName();
      value = XMLHelper.getNodeText(nodes.item(i));
      if (value == null)
      {
        value = "";
      }
      params.add(new NameValuePair(name, value));
    }

    /*
     * Copy WILDCARDS from XBUSSystem into parameters
     */
    Hashtable info = mDestination.getAddresses();
    String key = null;
    for (Enumeration en = info.keys(); en.hasMoreElements();)
    {
      key = (String) en.nextElement();
      if (XBUSSystem.FILENAME_WILDCARD.equals(key))
      {
        value = (String) info.get(key);
        params.add(new NameValuePair(key, value));
      }
    }

    NameValuePair[] paramArray = new NameValuePair[params.size()];
    params.copyInto(paramArray);
    method.setQueryString(paramArray);

    String response = sendMessage(method);
    return XMLHelper.parseXML(response, "Default", mDestination.getName());
  }
View Full Code Here

    }
  }

  public HTTPRequest head() {
    // FIXME: Allow HEAD request to send a message body?
    HttpMethodBase method = new PostMethod(url) {

      @Override
      public String getName() {
        return "HEAD";
      }
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.methods.PostMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.