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


Java StringRequestEntity类代码示例

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


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

示例1: loginToOntarioMD

import org.apache.commons.httpclient.methods.StringRequestEntity; //导入依赖的package包/类
public Hashtable loginToOntarioMD(String username,String password,String incomingRequestor) throws Exception{
    //public ArrayList soapHttpCall(int siteCode, String userId, String passwd,		String xml) throws Exception
    Hashtable h  = null;
    PostMethod post = new PostMethod("https://www.ontariomd.ca/services/OMDAutomatedAuthentication");
    post.setRequestHeader("SOAPAction", "");
    post.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

    String soapMsg = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><ns1:getSession xmlns:ns1=\"urn:OMDAutomatedAuthentication\"><username>"+username+"</username><password>"+password+"</password><incomingRequestor>"+incomingRequestor+"</incomingRequestor></ns1:getSession></soap:Body></soap:Envelope> ";

    RequestEntity re = new StringRequestEntity(soapMsg, "text/xml", "utf-8");

    post.setRequestEntity(re);

    HttpClient httpclient = new HttpClient();
    // Execute request
    try{
            httpclient.executeMethod(post);
            h = parseReturn(post.getResponseBodyAsStream());
    }catch(Exception e ){
        MiscUtils.getLogger().error("Error", e);
    } finally{
            // Release current connection to the connection pool
            post.releaseConnection();
    }
    return h;
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:27,代码来源:OntarioMD.java

示例2: testRussianInRequestBody

import org.apache.commons.httpclient.methods.StringRequestEntity; //导入依赖的package包/类
public void testRussianInRequestBody() throws IOException {
    PostMethod httppost = new PostMethod("/");
    String s = constructString(RUSSIAN_STUFF_UNICODE);
    // Test UTF-8 encoding
    httppost.setRequestEntity(
        new StringRequestEntity(s, "text/plain", CHARSET_UTF8));
    verifyEncoding(httppost.getRequestEntity(), RUSSIAN_STUFF_UTF8);
    // Test KOI8-R
    httppost.setRequestEntity(
        new StringRequestEntity(s, "text/plain", CHARSET_KOI8_R));
    verifyEncoding(httppost.getRequestEntity(), RUSSIAN_STUFF_KOI8R);
    // Test WIN1251
    httppost.setRequestEntity(
        new StringRequestEntity(s, "text/plain", CHARSET_WIN1251));
    verifyEncoding(httppost.getRequestEntity(), RUSSIAN_STUFF_WIN1251);
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:17,代码来源:TestMethodCharEncoding.java

示例3: testPostProxyAuthHostAuthConnClose

import org.apache.commons.httpclient.methods.StringRequestEntity; //导入依赖的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: doPut

import org.apache.commons.httpclient.methods.StringRequestEntity; //导入依赖的package包/类
public String doPut(String url, String charset, String jsonObj) {
    String resStr = null;
    HttpClient htpClient = new HttpClient();
    PutMethod putMethod = new PutMethod(url);
    putMethod.getParams().setParameter(
            HttpMethodParams.HTTP_CONTENT_CHARSET, charset);
    try {
        putMethod.setRequestEntity(new StringRequestEntity(jsonObj,
                "application/json", charset));
        int statusCode = htpClient.executeMethod(putMethod);
        if (statusCode != HttpStatus.SC_OK) {
            log.error("Method failed: " + putMethod.getStatusLine());
            return null;
        }
        byte[] responseBody = putMethod.getResponseBody();
        resStr = new String(responseBody, charset);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        putMethod.releaseConnection();
    }
    return resStr;
}
 
开发者ID:BriData,项目名称:DBus,代码行数:24,代码来源:HttpRequest.java

示例5: post

import org.apache.commons.httpclient.methods.StringRequestEntity; //导入依赖的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

示例6: testPostHostAuthConnKeepAlive

import org.apache.commons.httpclient.methods.StringRequestEntity; //导入依赖的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

示例7: testPostHostAuthConnClose

import org.apache.commons.httpclient.methods.StringRequestEntity; //导入依赖的package包/类
/**
 * Tests POST via non-authenticating proxy + host auth + connection close 
 */
public void testPostHostAuthConnClose() 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", false));
    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: testPostHostInvalidAuth

import org.apache.commons.httpclient.methods.StringRequestEntity; //导入依赖的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

示例9: testPostInteractiveHostAuthConnKeepAlive

import org.apache.commons.httpclient.methods.StringRequestEntity; //导入依赖的package包/类
/**
 * Tests POST via non-authenticating proxy + interactive host auth + connection keep-alive 
 */
public void testPostInteractiveHostAuthConnKeepAlive() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    this.client.getParams().setParameter(CredentialsProvider.PROVIDER, 
            new GetItWrongThenGetItRight());
    
    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,代码行数:27,代码来源:TestProxy.java

示例10: testPostInteractiveHostAuthConnClose

import org.apache.commons.httpclient.methods.StringRequestEntity; //导入依赖的package包/类
/**
 * Tests POST via non-authenticating proxy + interactive host auth + connection close 
 */
public void testPostInteractiveHostAuthConnClose() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    this.client.getParams().setParameter(CredentialsProvider.PROVIDER, 
            new GetItWrongThenGetItRight());
            
    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds, "test", false));
    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,代码行数:27,代码来源:TestProxy.java

示例11: testPostAuthProxy

import org.apache.commons.httpclient.methods.StringRequestEntity; //导入依赖的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

示例12: testPostProxyAuthHostAuthConnKeepAlive

import org.apache.commons.httpclient.methods.StringRequestEntity; //导入依赖的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

示例13: testPostInteractiveProxyAuthHostAuthConnKeepAlive

import org.apache.commons.httpclient.methods.StringRequestEntity; //导入依赖的package包/类
/**
 * Tests POST via non-authenticating proxy + interactive host auth + connection keep-alive 
 */
public void testPostInteractiveProxyAuthHostAuthConnKeepAlive() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    this.client.getParams().setParameter(CredentialsProvider.PROVIDER, 
            new GetItWrongThenGetItRight());
    
    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

示例14: testPostInteractiveProxyAuthHostAuthConnClose

import org.apache.commons.httpclient.methods.StringRequestEntity; //导入依赖的package包/类
/**
 * Tests POST via non-authenticating proxy + interactive host auth + connection close 
 */
public void testPostInteractiveProxyAuthHostAuthConnClose() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    this.client.getParams().setParameter(CredentialsProvider.PROVIDER, 
            new GetItWrongThenGetItRight());
            
    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

示例15: getPostResponseHeader

import org.apache.commons.httpclient.methods.StringRequestEntity; //导入依赖的package包/类
public static String getPostResponseHeader(String url,String argJson,List<UHeader> headerList,String headerName){
  	String info = "";
  	try {
   	HttpClient client = new HttpClient();
	PostMethod method = new PostMethod(url);
	client.getParams().setContentCharset("UTF-8");
	if(headerList.size()>0){
		for(int i = 0;i<headerList.size();i++){
			UHeader header = headerList.get(i);
			method.setRequestHeader(header.getHeaderTitle(),header.getHeaderValue());
		}
	}
	method.getParams().setParameter(
			HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
	if(argJson != null && !argJson.trim().equals("")) {
		RequestEntity requestEntity = new StringRequestEntity(argJson,"application/json","UTF-8");
		method.setRequestEntity(requestEntity);
	}
	method.releaseConnection();
	Header h =  method.getResponseHeader(headerName);
	info = h.getValue();
} catch (IOException e) {
	e.printStackTrace();
}
  	return info;
  }
 
开发者ID:noseparte,项目名称:Spring-Boot-Server,代码行数:27,代码来源:HttpUtils.java


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