/*
*示例仅供参考,请求参数及调用地址以文档为准
**/
import java.io.IOException;
import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
public class UrlConnection {
private static Logger logger = LogManager.getLogger("send");
public static String doGetRequest(String urlstr) {
String resp = null;
HttpClient client = new HttpClient(
new MultiThreadedHttpConnectionManager());
HttpMethod httpmethod = new GetMethod(urlstr);
try {
httpmethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler());
int statusCode = client.executeMethod(httpmethod);
if (statusCode == HttpStatus.SC_OK) {
resp = httpmethod.getResponseBodyAsString();
}
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
httpmethod.releaseConnection();
}
return resp;
}
public static void main(String[] args){
//发送
String url = "http://api.52ao.com/?user=test&pass=faea920f7412b5da7be0cf42b8c93759&mobile=13612345678&content=hello";
String responseValue = new UrlConnection().doGetRequest(url);
System.out.println("响应结果:"+responseValue);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
动动客短信HTTP接口
共14个文件
txt:6个
jar:4个
java:3个
5星 · 超过95%的资源 需积分: 22 10 下载量 44 浏览量
2015-04-05
17:25:11
上传
评论
收藏 587KB RAR 举报
温馨提示
/* *示例仅供参考,请求参数及调用地址以文档为准 **/ $url=''; echo Get($url); function Get($url) { if(function_exists('file_get_contents')) { $file_contents = file_get_contents($url); } else { $ch = curl_init(); $timeout = 5; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $file_contents = curl_exec($ch); curl_close($ch); } return $file_contents; }
资源推荐
资源详情
资源评论
收起资源包目录
SSMP.rar (14个子文件)
c#接入SSMP示例.txt 803B
上海希奥HTTP接口调用说明1.2.doc 84KB
vb接入SSMP示例.txt 524B
lib
commons-httpclient-3.1.jar 298KB
commons-codec-1.3.jar 46KB
commons-logging-1.0.4.jar 37KB
commons-lang-2.3.jar 240KB
asp接入SSMP示例.txt 910B
java示例
SendTest_Post.java 1KB
SendTest_Get.java 2KB
ReceiveMo.java 1KB
c++接入SSMP示例.txt 1KB
php接入SSMP示例.txt 466B
java接入SSMP示例.txt 2KB
共 14 条
- 1
资源评论
- 小蚂蚁20192018-09-10有用有用有用
evon1688
- 粉丝: 6
- 资源: 39
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- record record record record record record record record record
- Android 启动提示Android 正在升级...提示源码分析
- pojie-drawio-confluence-plugin-9.5.8.obr
- 信息学奥赛2020年NOIP真题
- SunloginClient-15.1.0.58718-x64.exe
- 信息学奥赛2021年NOIP真题
- 星辰语义大模型TeleChat超详细部署文档手册
- python range函数.pdf
- 许子昊毕业论文初稿-基于响应式编程的水质设备监测平台的设计与实现-定稿格式.docx
- musicManager.jsp
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功