當前位置: 首頁>>代碼示例>>Java>>正文


Java PostMethod.setRequestEntity方法代碼示例

本文整理匯總了Java中org.apache.commons.httpclient.methods.PostMethod.setRequestEntity方法的典型用法代碼示例。如果您正苦於以下問題:Java PostMethod.setRequestEntity方法的具體用法?Java PostMethod.setRequestEntity怎麽用?Java PostMethod.setRequestEntity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.httpclient.methods.PostMethod的用法示例。


在下文中一共展示了PostMethod.setRequestEntity方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: post

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public HttpResponse post(final RequestContext rq, final String scope, final int version, final String entityCollectionName, final Object entityId,
            final String relationCollectionName, final Object relationshipEntityId, final String body, String contentType, final Map<String, String> params) throws IOException
{
    RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), scope, version, entityCollectionName, entityId, relationCollectionName,
                relationshipEntityId, params);
    String url = endpoint.getUrl();

    PostMethod req = new PostMethod(url.toString());
    if (body != null)
    {
        if (contentType == null || contentType.isEmpty())
        {
            contentType = "application/json";
        }
        StringRequestEntity requestEntity = new StringRequestEntity(body, contentType, "UTF-8");
        req.setRequestEntity(requestEntity);
    }
    return submitRequest(req, rq);
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:20,代碼來源:PublicApiHttpClient.java

示例2: 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

示例3: testPostFilePart

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
/**
 * Test that the body consisting of a file part can be posted.
 */
public void testPostFilePart() throws Exception {
    
    this.server.setHttpService(new EchoService());

    PostMethod method = new PostMethod();
    byte[] content = "Hello".getBytes();
    MultipartRequestEntity entity = new MultipartRequestEntity(
        new Part[] { 
            new FilePart(
                "param1", 
                new ByteArrayPartSource("filename.txt", content), 
                "text/plain", 
                "ISO-8859-1") },
        method.getParams());
    method.setRequestEntity(entity);

    client.executeMethod(method);

    assertEquals(200,method.getStatusCode());
    String body = method.getResponseBodyAsString();
    assertTrue(body.indexOf("Content-Disposition: form-data; name=\"param1\"; filename=\"filename.txt\"") >= 0);
    assertTrue(body.indexOf("Content-Type: text/plain; charset=ISO-8859-1") >= 0);
    assertTrue(body.indexOf("Content-Transfer-Encoding: binary") >= 0);
    assertTrue(body.indexOf("Hello") >= 0);
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:29,代碼來源:TestMultipartPost.java

示例4: 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

示例5: testPostHostInvalidAuth

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
/**
 * Tests POST via non-authenticating proxy + invalid host auth 
 */
public void testPostHostInvalidAuth() throws Exception {

    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    this.client.getState().setCredentials(AuthScope.ANY, creds);
    
    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds));
    handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
    
    this.client.getState().setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials("testuser", "wrongstuff"));
    
    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_UNAUTHORIZED, post.getStatusCode());
    } finally {
        post.releaseConnection();
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:29,代碼來源:TestProxy.java

示例6: testEnclosedEntityExplicitLength

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public void testEnclosedEntityExplicitLength() 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);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        assertEquals(200, method.getStatusCode());
        String body = method.getResponseBodyAsString();
        assertEquals("This is a test", body);
        assertNull(method.getRequestHeader("Transfer-Encoding"));
        assertNotNull(method.getRequestHeader("Content-Length"));
        assertEquals(14, Integer.parseInt(
                method.getRequestHeader("Content-Length").getValue()));
    } finally {
        method.releaseConnection();
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:24,代碼來源:TestEntityEnclosingMethod.java

示例7: 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

示例8: testPostAuthProxy

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
/**
 * Tests POST via authenticating proxy
 */
public void testPostAuthProxy() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    this.client.getState().setProxyCredentials(AuthScope.ANY, creds);
    this.server.setHttpService(new FeedbackService());

    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,代碼行數:23,代碼來源:TestProxy.java

示例9: testEnclosedEntityAutoLength

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public void testEnclosedEntityAutoLength() 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);
    this.server.setHttpService(new EchoService());
    try {
        this.client.executeMethod(method);
        assertEquals(200, method.getStatusCode());
        String body = method.getResponseBodyAsString();
        assertEquals(inputstr, body);
        assertNull(method.getRequestHeader("Transfer-Encoding"));
        assertNotNull(method.getRequestHeader("Content-Length"));
        assertEquals(input.length, Integer.parseInt(
                method.getRequestHeader("Content-Length").getValue()));
    } finally {
        method.releaseConnection();
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:24,代碼來源:TestEntityEnclosingMethod.java

示例10: testPostStringPart

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
/**
 * Test that the body consisting of a string part can be posted.
 */
public void testPostStringPart() throws Exception {
    
    this.server.setHttpService(new EchoService());
    
    PostMethod method = new PostMethod();
    MultipartRequestEntity entity = new MultipartRequestEntity(
        new Part[] { new StringPart("param", "Hello", "ISO-8859-1") },
        method.getParams());
    method.setRequestEntity(entity);
    client.executeMethod(method);

    assertEquals(200,method.getStatusCode());
    String body = method.getResponseBodyAsString();
    assertTrue(body.indexOf("Content-Disposition: form-data; name=\"param\"") >= 0);
    assertTrue(body.indexOf("Content-Type: text/plain; charset=ISO-8859-1") >= 0);
    assertTrue(body.indexOf("Content-Transfer-Encoding: 8bit") >= 0);
    assertTrue(body.indexOf("Hello") >= 0);
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:22,代碼來源:TestMultipartPost.java

示例11: testPostFilePartUnknownLength

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public void testPostFilePartUnknownLength() throws Exception {
    
    this.server.setHttpService(new EchoService());

    String enc = "ISO-8859-1";
    PostMethod method = new PostMethod();
    byte[] content = "Hello".getBytes(enc);
    MultipartRequestEntity entity = new MultipartRequestEntity(
        new Part[] { 
            new FilePart(
                "param1", 
                new TestPartSource("filename.txt", content), 
                 "text/plain", 
                 enc) },
         method.getParams());
    method.setRequestEntity(entity);

    client.executeMethod(method);

    assertEquals(200,method.getStatusCode());
    String body = method.getResponseBodyAsString();
    assertTrue(body.indexOf("Content-Disposition: form-data; name=\"param1\"; filename=\"filename.txt\"") >= 0);
    assertTrue(body.indexOf("Content-Type: text/plain; charset="+enc) >= 0);
    assertTrue(body.indexOf("Content-Transfer-Encoding: binary") >= 0);
    assertTrue(body.indexOf("Hello") >= 0);
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:27,代碼來源:TestMultipartPost.java

示例12: createPostMethod

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
/**
 * 
 * @param doc
 *            Document with body info
 * @param route
 *            Pay or Preapproval
 * @return the PostMethod to be invoked
 * @throws TransformerException
 *             on bad xml input or transformer exceptions
 */
private PostMethod createPostMethod(Document doc, String route)
        throws TransformerException {
    final PostMethod postMethod = new PostMethod(PAYPAL_URL + '/' + route);

    // communication format
    postMethod.addRequestHeader("X-PAYPAL-REQUEST-DATA-FORMAT", "XML");
    postMethod.addRequestHeader("X-PAYPAL-RESPONSE-DATA-FORMAT", "XML");

    // authentication info
    postMethod.addRequestHeader("X-PAYPAL-SECURITY-USERID",
            "mercha_1310720134_biz_api1.est.fujitsu.com");
    postMethod.addRequestHeader("X-PAYPAL-SECURITY-PASSWORD", "1310720175");
    postMethod.addRequestHeader("X-PAYPAL-SECURITY-SIGNATURE",
            "AlTG0c2puvFWih-1mR5Tn9-Pbx6MAyndXBaCr0Cmgec8UBYC7Kty76vJ");
    postMethod.addRequestHeader("X-PAYPAL-APPLICATION-ID",
            "APP-80W284485P519543T");
    postMethod.addRequestHeader("X-PAYPAL-DEVICE-IPADDRESS", remoteIpAddr);
    try {
        postMethod.setRequestEntity(new StringRequestEntity(
                getDocAsString(doc), "text/xml", "UTF-8"));
    } catch (UnsupportedEncodingException ex) {
        // UTF-8 is always supported, so this exception should never been
        // thrown
        throw new RuntimeException(ex);
    }
    return postMethod;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:38,代碼來源:PaypalRequest.java

示例13: testLatinAccentInRequestBody

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public void testLatinAccentInRequestBody() throws IOException {
    PostMethod httppost = new PostMethod("/");
    String s = constructString(SWISS_GERMAN_STUFF_UNICODE);
    // Test default encoding ISO-8859-1
    httppost.setRequestEntity(
        new StringRequestEntity(s, "text/plain", CHARSET_DEFAULT));
    verifyEncoding(httppost.getRequestEntity(), SWISS_GERMAN_STUFF_ISO8859_1);
    // Test UTF-8 encoding
    httppost.setRequestEntity(
        new StringRequestEntity(s, "text/plain", CHARSET_UTF8));
    verifyEncoding(httppost.getRequestEntity(), SWISS_GERMAN_STUFF_UTF8);

}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:14,代碼來源:TestMethodCharEncoding.java

示例14: createPostMethod

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
/**
 * Creates the post method used to send the SOAP request.
 * 
 * @param endpoint endpoint to which the message is sent
 * @param requestParams HTTP request parameters
 * @param message message to be sent
 * 
 * @return the post method to be used to send this message
 * 
 * @throws SOAPClientException thrown if the message could not be marshalled
 */
protected PostMethod createPostMethod(String endpoint, HttpSOAPRequestParameters requestParams, Envelope message)
        throws SOAPClientException {
    log.debug("POSTing SOAP message to {}", endpoint);

    PostMethod post = new PostMethod(endpoint);
    post.setRequestEntity(createRequestEntity(message, Charset.forName("UTF-8")));
    if (requestParams != null && requestParams.getSoapAction() != null) {
        post.setRequestHeader(HttpSOAPRequestParameters.SOAP_ACTION_HEADER, requestParams.getSoapAction());
    }

    return post;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:24,代碼來源:HttpSOAPClient.java

示例15: testSimplePost

import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
/**
 * Tests POST via non-authenticating proxy
 */
public void testSimplePost() throws Exception {
    this.server.setHttpService(new FeedbackService());
    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,代碼行數:16,代碼來源:TestProxy.java


注:本文中的org.apache.commons.httpclient.methods.PostMethod.setRequestEntity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。