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


Java PutMethod.getResponseBody方法代碼示例

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


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

示例1: doPut

import org.apache.commons.httpclient.methods.PutMethod; //導入方法依賴的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

示例2: put

import org.apache.commons.httpclient.methods.PutMethod; //導入方法依賴的package包/類
/**
 * Send a PUT request
 * @param cluster the cluster definition
 * @param path the path or URI
 * @param headers the HTTP headers to include, <tt>Content-Type</tt> must be
 * supplied
 * @param content the content bytes
 * @return a Response object with response detail
 * @throws IOException
 */
public Response put(Cluster cluster, String path, Header[] headers, 
    byte[] content) throws IOException {
  PutMethod method = new PutMethod();
  try {
    method.setRequestEntity(new ByteArrayRequestEntity(content));
    int code = execute(cluster, method, headers, path);
    headers = method.getResponseHeaders();
    content = method.getResponseBody();
    return new Response(code, headers, content);
  } finally {
    method.releaseConnection();
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:24,代碼來源:Client.java

示例3: callPutFileApi

import org.apache.commons.httpclient.methods.PutMethod; //導入方法依賴的package包/類
private void callPutFileApi(String fileType, String url, String filePath, String oui, String prodClass, String version) throws HttpException, IOException, HitDMException {
	org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient();
	
	PutMethod putMethod = new PutMethod(url);
	File input = new File(filePath);
	RequestEntity entity = new FileRequestEntity(input, "Content-Length: 1431");
	putMethod.setRequestEntity(entity);
	putMethod.setRequestHeader("fileType", fileType);
	putMethod.setRequestHeader("oui", oui);
	putMethod.setRequestHeader("productClass", prodClass);
	putMethod.setRequestHeader("version", version);
	
	client.executeMethod(putMethod);
	
	if (putMethod.getStatusCode() != 200) {
		String debugStr = "DM Server return:"+ putMethod.getStatusCode();
		byte[] body;
		try {
			body = putMethod.getResponseBody();
			if (body != null) {
				debugStr += "\r\nBody:"+new String(body);
			}
		} catch (Exception e) {
			debugStr += e.getMessage();
		}
		
		throw new HitDMException(putMethod.getStatusCode(), debugStr);
	}
	
}
 
開發者ID:iotoasis,項目名稱:SI,代碼行數:31,代碼來源:Tr069DMAdapter.java

示例4: testPutProduct

import org.apache.commons.httpclient.methods.PutMethod; //導入方法依賴的package包/類
public void testPutProduct() throws HttpException, IOException{
	
	PutMethod method=new PutMethod("http://localhost:8080/sqlrest/PRODUCT/83/");
	RequestEntity body=new StringRequestEntity(PUT_NEW_PRODUCT);
	method.setRequestEntity(body);
	int status=client.executeMethod(method);
	assertEquals(201, status);
	byte[] response =method.getResponseBody();
	assertNotNull(response);
	assertTrue(response.length==0);
}
 
開發者ID:predic8,項目名稱:sqlrest,代碼行數:12,代碼來源:MainServletTest.java


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