當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。