当前位置: 首页>>代码示例>>Java>>正文


Java PostMethod类代码示例

本文整理汇总了Java中org.apache.commons.httpclient.methods.PostMethod的典型用法代码示例。如果您正苦于以下问题:Java PostMethod类的具体用法?Java PostMethod怎么用?Java PostMethod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PostMethod类属于org.apache.commons.httpclient.methods包,在下文中一共展示了PostMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: httpClientPost

import org.apache.commons.httpclient.methods.PostMethod; //导入依赖的package包/类
public static final String httpClientPost(String url, ArrayList<NameValuePair> list) {
    String result = "";
    HttpClient client = new HttpClient();
    PostMethod postMethod = new PostMethod(url);
    try {
        NameValuePair[] params = new NameValuePair[list.size()];
        for (int i = 0; i < list.size(); i++) {
            params[i] = list.get(i);
        }
        postMethod.addParameters(params);
        client.executeMethod(postMethod);
        result = postMethod.getResponseBodyAsString();
    } catch (Exception e) {
        logger.error("", e);
    } finally {
        postMethod.releaseConnection();
    }
    return result;
}
 
开发者ID:iBase4J,项目名称:iBase4J-Common,代码行数:20,代码来源:HttpUtil.java

示例2: post

import org.apache.commons.httpclient.methods.PostMethod; //导入依赖的package包/类
@Override
public HttpResponse post(URL urlObj, byte[] payload, String userName, String password,
                         int timeout) {
  HttpClient client = new HttpClient();
  PostMethod method = new PostMethod(urlObj.toString());
  method.setRequestEntity(new ByteArrayRequestEntity(payload));
  method.setRequestHeader("Content-type", "application/json");
  client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
      new DefaultHttpMethodRetryHandler());
  client.getParams().setSoTimeout(1000 * timeout);
  client.getParams().setConnectionManagerTimeout(1000 * timeout);
  if (userName != null && password != null) {
    setBasicAuthorization(method, userName, password);
  }
  try {
    int response = client.executeMethod(method);
    return new HttpResponse(response, method.getResponseBody());
  } catch (IOException e) {
    throw new RuntimeException("Failed to process post request URL: " + urlObj, e);
  } finally {
    method.releaseConnection();
  }

}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:25,代码来源:LogiURLFetchService.java

示例3: testPostProxyAuthHostAuthConnClose

import org.apache.commons.httpclient.methods.PostMethod; //导入依赖的package包/类
/**
 * Tests POST via authenticating proxy + host auth + connection close 
 */
public void testPostProxyAuthHostAuthConnClose() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    this.client.getState().setCredentials(AuthScope.ANY, creds);
    this.client.getState().setProxyCredentials(AuthScope.ANY, creds);
    
    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds, "test", false));
    handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
    
    this.server.setRequestHandler(handlerchain);
    
    this.proxy.requireAuthentication(creds, "test", true);

    PostMethod post = new PostMethod("/");
    post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null));
    try {
        this.client.executeMethod(post);
        assertEquals(HttpStatus.SC_OK, post.getStatusCode());
        assertNotNull(post.getResponseBodyAsString());
    } finally {
        post.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:29,代码来源:TestProxy.java

示例4: chcekConnectionStatus

import org.apache.commons.httpclient.methods.PostMethod; //导入依赖的package包/类
public void chcekConnectionStatus() throws IOException {

        HttpClient httpClient = new HttpClient();
        //TODO : add connection details while testing only,remove it once done
        String teradatajson = "{\"username\":\"\",\"password\":\"\",\"hostname\":\"\",\"database\":\"\",\"dbtype\":\"\",\"port\":\"\"}";
        PostMethod postMethod = new PostMethod("http://" + HOST_NAME + ":" + PORT + "/getConnectionStatus");

        //postMethod.addParameter("request_parameters", redshiftjson);
        postMethod.addParameter("request_parameters", teradatajson);

        int response = httpClient.executeMethod(postMethod);
        InputStream inputStream = postMethod.getResponseBodyAsStream();

        byte[] buffer = new byte[1024 * 1024 * 5];
        String path = null;
        int length;
        while ((length = inputStream.read(buffer)) > 0) {
            path = new String(buffer);
        }
        System.out.println("Response of service: " + path);
        System.out.println("==================");
    }
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:23,代码来源:HydrographServiceClient.java

示例5: calltoReadService

import org.apache.commons.httpclient.methods.PostMethod; //导入依赖的package包/类
public void calltoReadService() throws IOException {

        HttpClient httpClient = new HttpClient();

        PostMethod postMethod = new PostMethod("http://" + HOST_NAME + ":" + PORT + "/read");
        postMethod.addParameter("jobId", JOB_ID);
        postMethod.addParameter("componentId", COMPONENT_ID);
        postMethod.addParameter("socketId", SOCKET_ID);
        postMethod.addParameter("basePath", BASE_PATH);
        postMethod.addParameter("userId", USER_ID);
        postMethod.addParameter("password", PASSWORD);
        postMethod.addParameter("file_size", FILE_SIZE_TO_READ);
        postMethod.addParameter("host_name", HOST_NAME);

        InputStream inputStream = postMethod.getResponseBodyAsStream();

        byte[] buffer = new byte[1024 * 1024 * 5];
        String path = null;
        int length;
        while ((length = inputStream.read(buffer)) > 0) {
            path = new String(buffer);
        }
        System.out.println("response of service: " + path);
    }
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:25,代码来源:HydrographServiceClient.java

示例6: httpClientPost

import org.apache.commons.httpclient.methods.PostMethod; //导入依赖的package包/类
public static final String httpClientPost(String url, ArrayList<NameValuePair> list) {
	String result = "";
	HttpClient client = new HttpClient();
	PostMethod postMethod = new PostMethod(url);
	try {
		NameValuePair[] params = new NameValuePair[list.size()];
		for (int i = 0; i < list.size(); i++) {
			params[i] = list.get(i);
		}
		postMethod.addParameters(params);
		client.executeMethod(postMethod);
		result = postMethod.getResponseBodyAsString();
	} catch (Exception e) {
		logger.error(e);
	} finally {
		postMethod.releaseConnection();
	}
	return result;
}
 
开发者ID:guokezheng,项目名称:automat,代码行数:20,代码来源:HttpUtil.java

示例7: testPostHostAuthConnKeepAlive

import org.apache.commons.httpclient.methods.PostMethod; //导入依赖的package包/类
/**
 * Tests POST via non-authenticating proxy + host auth + connection keep-alive 
 */
public void testPostHostAuthConnKeepAlive() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    this.client.getState().setCredentials(AuthScope.ANY, creds);
    
    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds, "test", true));
    handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
    
    this.server.setRequestHandler(handlerchain);
    
    PostMethod post = new PostMethod("/");
    post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null));
    try {
        this.client.executeMethod(post);
        assertEquals(HttpStatus.SC_OK, post.getStatusCode());
        assertNotNull(post.getResponseBodyAsString());
    } finally {
        post.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:26,代码来源:TestProxy.java

示例8: testEnclosedEntityNegativeLengthHTTP1_0

import org.apache.commons.httpclient.methods.PostMethod; //导入依赖的package包/类
public void testEnclosedEntityNegativeLengthHTTP1_0() throws Exception {
    
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, -14); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    method.setContentChunked(false);
    method.getParams().setVersion(HttpVersion.HTTP_1_0);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        fail("ProtocolException should have been thrown");
    } catch (ProtocolException ex) {
        // expected
    } finally {
        method.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:23,代码来源:TestEntityEnclosingMethod.java

示例9: buildPayRequest

import org.apache.commons.httpclient.methods.PostMethod; //导入依赖的package包/类
/**
 * Creates a pay request from the buyer (who is indirectly referenced by the
 * preapproval key) to the seller/receiver.
 * 
 * @param preapprovalKey
 *            The key from a former preapproval request
 * @param amount
 *            amount to be transfered in Euro
 * @return
 * @throws Exception
 */
public PostMethod buildPayRequest(String preapprovalKey, String receiver,
        String amount) throws Exception {
    final Document doc = createBody("PayRequest");
    final Element payReq = doc.getDocumentElement();

    addElement(payReq, "actionType", "PAY");
    addElement(payReq, "preapprovalKey", preapprovalKey);
    addElement(payReq, "senderEmail",
            "[email protected]");

    final Element receiverList = addElement(payReq, "receiverList", null);
    final Element receiverElement = addElement(receiverList, "receiver",
            null);

    addElement(receiverElement, "amount", amount);
    addElement(receiverElement, "email", receiver);
    return createPostMethod(doc, "Pay");
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:30,代码来源:PaypalRequest.java

示例10: doPost

import org.apache.commons.httpclient.methods.PostMethod; //导入依赖的package包/类
/**
 * Sends the request to paypal. Input is preapprovalKey of buyer, email of
 * seller, and amount to be transferred.
 * 
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
 *      response)
 */
protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    try {
        final PaypalRequest paypalRequest = new PaypalRequest(
                request.getRemoteAddr());
        final PostMethod post = paypalRequest.buildPayRequest(
                request.getParameter("preapprovalKey"),
                request.getParameter("email"),
                request.getParameter("amount"));

        setDefaultAttributes(request, paypalRequest,
                sendPaypalRequest(post));

        request.getRequestDispatcher("/payResponse.jsp").forward(request,
                response);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:27,代码来源:PayServlet.java

示例11: testPostProxyAuthHostAuthConnKeepAlive

import org.apache.commons.httpclient.methods.PostMethod; //导入依赖的package包/类
/**
 * Tests POST via authenticating proxy + host auth + connection keep-alive 
 */
public void testPostProxyAuthHostAuthConnKeepAlive() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    this.client.getState().setCredentials(AuthScope.ANY, creds);
    this.client.getState().setProxyCredentials(AuthScope.ANY, creds);
    
    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds, "test", true));
    handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
    
    this.server.setRequestHandler(handlerchain);
    
    this.proxy.requireAuthentication(creds, "test", true);

    PostMethod post = new PostMethod("/");
    post.setRequestEntity(new StringRequestEntity("Like tons of stuff", null, null));
    try {
        this.client.executeMethod(post);
        assertEquals(HttpStatus.SC_OK, post.getStatusCode());
        assertNotNull(post.getResponseBodyAsString());
    } finally {
        post.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:29,代码来源:TestProxy.java

示例12: toString

import org.apache.commons.httpclient.methods.PostMethod; //导入依赖的package包/类
/**
 * Help method for log
 *
 * @param method method
 */
protected void toString(HttpMethod method) {
    logger.info("===============HTTP METHOD===============");
    final String path = method.getPath();
    logger.info("path = " + path);
    final Header[] headers = method.getRequestHeaders();
    StringBuilder builder = new StringBuilder();
    for (Header header : headers) {
        if (header != null)
            builder.append(header.toString());
    }
    logger.info("header = \n" + builder.toString().trim());
    if (method instanceof PostMethod) {
        PostMethod postMethod = (PostMethod) method;
        builder = new StringBuilder();
        final NameValuePair[] parameters = postMethod.getParameters();
        for (NameValuePair pair : parameters) {
            builder.append(pair.getName()).append("=").append(pair.getValue()).append("\n");
        }
    }
    logger.info("post parameters: \n" + builder.toString().trim());
    logger.info("query string = " + method.getQueryString());
    logger.info("=========================================");
}
 
开发者ID:jhkst,项目名称:dlface,代码行数:29,代码来源:DownloadClient.java

示例13: createPostMethod

import org.apache.commons.httpclient.methods.PostMethod; //导入依赖的package包/类
private PostMethod createPostMethod(KalturaParams kparams,
		KalturaFiles kfiles, String url) {
	PostMethod method = new PostMethod(url);
       method.setRequestHeader("Accept","text/xml,application/xml,*/*");
       method.setRequestHeader("Accept-Charset","utf-8,ISO-8859-1;q=0.7,*;q=0.5");
       
       if (!kfiles.isEmpty()) {        	
           method = this.getPostMultiPartWithFiles(method, kparams, kfiles);        	
       } else {
           method = this.addParams(method, kparams);            
       }
       
       if (isAcceptGzipEncoding()) {
		method.addRequestHeader(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
	}
       

	// Provide custom retry handler is necessary
	method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
			new DefaultHttpMethodRetryHandler (3, false));
	return method;
}
 
开发者ID:ITYug,项目名称:kaltura-ce-sakai-extension,代码行数:23,代码来源:KalturaClientBase.java

示例14: testEnclosedEntityChunkedHTTP1_0

import org.apache.commons.httpclient.methods.PostMethod; //导入依赖的package包/类
public void testEnclosedEntityChunkedHTTP1_0() throws Exception {
    String inputstr = "This is a test message";
    byte[] input = inputstr.getBytes("US-ASCII");
    InputStream instream = new ByteArrayInputStream(input);
    
    RequestEntity requestentity = new InputStreamRequestEntity(
            instream, InputStreamRequestEntity.CONTENT_LENGTH_AUTO); 
    PostMethod method = new PostMethod("/");
    method.setRequestEntity(requestentity);
    method.setContentChunked(true);
    method.getParams().setVersion(HttpVersion.HTTP_1_0);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        fail("ProtocolException should have been thrown");
    } catch (ProtocolException ex) {
        // expected
    } finally {
        method.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:22,代码来源:TestEntityEnclosingMethod.java

示例15: getDebugFileMethod

import org.apache.commons.httpclient.methods.PostMethod; //导入依赖的package包/类
/**
 * 
 * Get post method to get csv debug file
 * 
 * @param jobDetails
 * @param fileSize
 * @return {@link PostMethod}
 * @throws NumberFormatException
 * @throws MalformedURLException
 */
public PostMethod getDebugFileMethod(JobDetails jobDetails,String fileSize) throws NumberFormatException, MalformedURLException {
	
	URL url = new URL(POST_PROTOCOL, getHost(jobDetails), getPortNo(jobDetails), DebugServiceMethods.GET_DEBUG_FILE_PATH);
			
	PostMethod postMethod = new PostMethod(url.toString());
	postMethod.addParameter(DebugServicePostParameters.JOB_ID, jobDetails.getUniqueJobID());
	postMethod.addParameter(DebugServicePostParameters.COMPONENT_ID, jobDetails.getComponentID());
	postMethod.addParameter(DebugServicePostParameters.SOCKET_ID, jobDetails.getComponentSocketID());
	postMethod.addParameter(DebugServicePostParameters.BASE_PATH, jobDetails.getBasepath());
	postMethod.addParameter(DebugServicePostParameters.USER_ID, jobDetails.getUsername());
	postMethod.addParameter(DebugServicePostParameters.DEBUG_SERVICE_PWD, jobDetails.getPassword());
	postMethod.addParameter(DebugServicePostParameters.FILE_SIZE, fileSize);
	postMethod.addParameter(DebugServicePostParameters.HOST_NAME, getHost(jobDetails));
	
	LOGGER.debug("Calling debug service to get csv debug file from url :: "+url);
	
	return postMethod;
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:29,代码来源:Provider.java


注:本文中的org.apache.commons.httpclient.methods.PostMethod类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。