use of org.apache.commons.httpclient.methods.PostMethod in project sling by apache.
the class PostResponseCreatorTest method testCustomPostResponseCreator.
public void testCustomPostResponseCreator() throws Exception {
final PostMethod post = new PostMethod(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX);
post.addParameter(":responseType", "custom");
post.setFollowRedirects(false);
final int status = httpClient.executeMethod(post);
assertEquals("Unexpected status response", 201, status);
assertEquals("Thanks!", post.getResponseBodyAsString());
post.releaseConnection();
}
use of org.apache.commons.httpclient.methods.PostMethod in project engine by craftercms.
the class HttpProxyImpl method createPostMethod.
protected HttpMethod createPostMethod(String url, HttpServletRequest request) throws IOException {
PostMethod postMethod = new PostMethod(url);
copyRequestHeadersToMethod(postMethod, request);
copyRequestBodyToMethod(postMethod, request);
return postMethod;
}
use of org.apache.commons.httpclient.methods.PostMethod in project dianping-open-sdk by dianping.
the class ApiTool method requestPostApi.
public static String requestPostApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap) {
StringBuffer response = new StringBuffer();
HttpClientParams httpConnectionParams = new HttpClientParams();
httpConnectionParams.setConnectionManagerTimeout(1000);
HttpClient client = new HttpClient(httpConnectionParams);
PostMethod method = new PostMethod(apiUrl);
try {
String sign = sign(appKey, secret, paramMap);
paramMap.put("sign", sign);
paramMap.put("appkey", appKey);
// 设置HTTP Post数据
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
method.addParameter(entry.getKey(), entry.getValue());
}
method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
client.executeMethod(method);
BufferedReader reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream(), "UTF-8"));
String line = null;
while ((line = reader.readLine()) != null) {
response.append(line).append(System.getProperty("line.separator"));
}
reader.close();
} catch (IOException e) {
LOGGER.error("Request URL: " + apiUrl + " failed. ", e);
} finally {
method.releaseConnection();
}
return response.toString();
}
use of org.apache.commons.httpclient.methods.PostMethod in project dianping-open-sdk by dianping.
the class DemoApiTool method requestPostApi.
public static String requestPostApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap) {
StringBuffer response = new StringBuffer();
HttpClientParams httpConnectionParams = new HttpClientParams();
httpConnectionParams.setConnectionManagerTimeout(1000);
HttpClient client = new HttpClient(httpConnectionParams);
PostMethod method = new PostMethod(apiUrl);
try {
String sign = sign(appKey, secret, paramMap);
paramMap.put("sign", sign);
paramMap.put("appkey", appKey);
// 设置HTTP Post数据
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
method.addParameter(entry.getKey(), entry.getValue());
}
method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
client.executeMethod(method);
BufferedReader reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream(), "UTF-8"));
String line = null;
while ((line = reader.readLine()) != null) {
response.append(line).append(System.getProperty("line.separator"));
}
reader.close();
} catch (IOException e) {
LOGGER.error("Request URL: " + apiUrl + " failed. ", e);
} finally {
method.releaseConnection();
}
return response.toString();
}
use of org.apache.commons.httpclient.methods.PostMethod in project camel by apache.
the class UndertowMethodRestricTest method testProperHttpMethod.
@Test
public void testProperHttpMethod() throws Exception {
HttpClient httpClient = new HttpClient();
PostMethod httpPost = new PostMethod(url);
StringRequestEntity reqEntity = new StringRequestEntity("This is a test", null, null);
httpPost.setRequestEntity(reqEntity);
int status = httpClient.executeMethod(httpPost);
assertEquals(200, status);
String result = httpPost.getResponseBodyAsString();
assertEquals("This is a test response", result);
}
Aggregations