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


Java PostMethod.addRequestHeader方法代码示例

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


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

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

示例2: runTest

import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
private void runTest(String acceptHeaderValue, boolean useHttpEquiv, String expectedContentType) throws Exception {
    final String info = (useHttpEquiv ? "Using http-equiv parameter" : "Using Accept header") + ": ";
    final String url = HTTP_BASE_URL + MY_TEST_PATH;
    final PostMethod post = new PostMethod(url);
    post.setFollowRedirects(false);
    
    if(acceptHeaderValue != null) {
        if(useHttpEquiv) {
            post.addParameter(":http-equiv-accept", acceptHeaderValue);
        } else {
            post.addRequestHeader("Accept", acceptHeaderValue);
        }
    }
    
    final int status = httpClient.executeMethod(post) / 100;
    assertEquals(info + "Expected status 20x for POST at " + url, 2, status);
    final Header h = post.getResponseHeader("Content-Type");
    assertNotNull(info + "Expected Content-Type header", h);
    final String ct = h.getValue();
    assertTrue(info + "Expected Content-Type '" + expectedContentType + "' for Accept header=" + acceptHeaderValue
            + " but got '" + ct + "'",
            ct.startsWith(expectedContentType));
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:24,代码来源:PostServletOutputContentTypeTest.java

示例3: testJsonContentTypeException

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

      // Perform a POST that fails: invalid PostServlet operation
      // with Accept header set to JSON  
      final String url = HTTP_BASE_URL + MY_TEST_PATH;
      final PostMethod post = new PostMethod(url);
      post.setFollowRedirects(false);
      post.addParameter(new NameValuePair(
          SlingPostConstants.RP_OPERATION,
          "InvalidTestOperationFor" + getClass().getSimpleName()));
      post.addRequestHeader("Accept", CONTENT_TYPE_JSON);

      final int status = httpClient.executeMethod(post);
      assertEquals(500, status);
      final String contentType = post.getResponseHeader("Content-Type").getValue();
      final String expected = CONTENT_TYPE_JSON;
      assertTrue("Expecting content-type " + expected + " for failed POST request, got " + contentType,
              contentType!=null && contentType.startsWith(expected));
    }
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:20,代码来源:PostServletOutputContentTypeTest.java

示例4: assertPostStatus

import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
protected HttpMethod assertPostStatus(String url, int expectedStatusCode, List<NameValuePair> postParams,
        List<Header> headers, String assertMessage) throws IOException {
    final PostMethod post = new PostMethod(url);
    post.setFollowRedirects(false);

    if (headers != null) {
        for (Header header : headers) {
            post.addRequestHeader(header);
        }
    }

    if (postParams != null) {
        final NameValuePair[] nvp = {};
        post.setRequestBody(postParams.toArray(nvp));
    }

    final int status = H.getHttpClient().executeMethod(post);
    if (assertMessage == null) {
        assertEquals(expectedStatusCode, status);
    } else {
        assertEquals(assertMessage, expectedStatusCode, status);
    }
    return post;
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:25,代码来源:AuthenticationResponseCodeTest.java

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

示例6: post

import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public String post(String postURL, Map<String, String> partam, String cookies)
            throws IOException {
//        clearCookies();
        PostMethod p = new PostMethod(postURL);
        for (String key : partam.keySet()) {
            if (partam.get(key) != null) {
                p.setParameter(key, partam.get(key));
            }
        }
        if (StringUtils.isNotEmpty(cookies)) {
            p.addRequestHeader("cookie", cookies);
        }
        hc.executeMethod(p);
        return p.getResponseBodyAsString();
    }
 
开发者ID:bruceq,项目名称:Gather-Platform,代码行数:16,代码来源:HttpClientUtil.java

示例7: getAccessTokenUserPass

import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public String getAccessTokenUserPass() {
    if (!StringUtils.isEmpty(this.oAuth2AccessToken)) {
        return this.oAuth2AccessToken;
    }

    if (StringUtils.isEmpty(this.username) || StringUtils.isEmpty(this.password) && StringUtils.isEmpty(this.oAuth2AuthorizationServer)
            || StringUtils.isEmpty(this.oAuth2ClientId) || StringUtils.isEmpty(this.oAuth2ClientSecret)) {
        return "";
    }

    try {
        HttpClient client = new HttpClient();
        client.getParams().setAuthenticationPreemptive(true);

        // post development
        PostMethod method = new PostMethod(this.getOAuthAuthorizationServer());
        method.setRequestHeader(new Header("Content-type", "application/x-www-form-urlencoded"));

        method.addRequestHeader("Authorization", "Basic " + Base64.encodeBase64String((username + ":" + password).getBytes()));
        NameValuePair[] body = new NameValuePair[] { new NameValuePair("username", username), new NameValuePair("password", password),
                new NameValuePair("client_id", oAuth2ClientId), new NameValuePair("client_secret", oAuth2ClientSecret),
                new NameValuePair("grant_type", oAuth2GrantType) };
        method.setRequestBody(body);
        int responseCode = client.executeMethod(method);

        String responseBody = method.getResponseBodyAsString();
        if (responseCode != 200) {
            throw new RuntimeException("Failed to fetch access token form authorization server, " + this.getOAuthAuthorizationServer()
                    + ", got response code " + responseCode);
        }

        JSONObject accessResponse = new JSONObject(responseBody);
        accessResponse.getString("access_token");
        return (this.oAuth2AccessToken = accessResponse.getString("access_token"));
    } catch (Exception e) {
        throw new RuntimeException("Failed to read response from authorizationServer at " + this.getOAuthAuthorizationServer(), e);
    }
}
 
开发者ID:wso2-incubator,项目名称:scim2-compliance-test-suite,代码行数:39,代码来源:CSP.java


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