资源简介
是一个Java 发送http put、delete、 post、 get 请求的工具类。可用在与restful service 进行通讯的代码中。
代码片段和文件信息
package com.ganji.as.restful.service.spi.intf;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import com.ganji.common.utils.HttpUtil;
/***
*
* @author yikangfeng
*
*/
class RestfulRequestHelper extends HttpUtil {
static private final Log LOG = LogFactory
.getLog(RestfulRequestHelper.class);
static public String sendPOST(String restfulUrl Map params) {
return doPost(restfulUrl params);
}
static public String sendDELETE(String restfulUrl
Map params) {
HttpClient client = new DefaultHttpClient();
HttpDelete requestDelete = new HttpDelete(restfulUrl);
requestDelete
.setHeader(“Accept“
“application/json application/xml text/html text/* image/* */*“);
String result = ““;
try {
HttpResponse httpResponse = client.execute(requestDelete);
if (httpResponse == null)
return result;
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
result = EntityUtils.toString(httpResponse.getEntity());
} catch (IOException ignore) {
ignore.printStackTrace();
if (LOG.isErrorEnabled())
LOG.error(ignore);
} finally {
if (client != null)
client
- 上一篇:Java反射应用
- 下一篇:Java 反射Reflection 经典实用
相关资源
- AutoInput破解版
- JFLAP 官方英文版
- fileinput+servlet+jdbc源码
- Android键盘AOSP监听delete按键2
- Computer Graphics for Java Programmers 2nd
- 随书代码Mastering OpenCV with Practical Co
- java实现读取word文件并且上传到数据库
- JAVA编程:统计英文文本文件中的字符
- send_mqtt.zip
- HTML+JAVA 手机端相册或者拍照上传到服
- okhttp-3.6.0.jar okhttputils-2_6_2.jar
- httputil工具类
- jsp\\No result defined for action and result i
- check_all_input_v1.1.zip
- PacketSender源码Android Studio版
- HttpUtil工具类支持POSTGETHTTPHTTPS
- 文件输出与读入
- 变速不变调播放mp3-QT-QAudioOutput
- OpenCV 3.0 Computer Vision with Java.pdf
- bitmaputil
- I/O流.xmind
- tasker 插件 AutoInput 最新中文破解版
- DWR弹出failed to read input...”
- listview ui 控件,不全选,增删查
评论
共有 条评论