本文整理匯總了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;
}
示例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();
}
}
示例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);
}
}
示例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);
}