HttpURLCollection调用短信接口
2014-12-11 16:36
274 查看
public String sendData() {
//更新发送时间
updateSendTime();
URL url;
try {
//System.out.println(postUrl+"?"+postData.toString());
url = new URL(postUrl+"?"+postData.toString());
hconn = (HttpURLConnection) url.openConnection();
// 设置提交方式
hconn.setRequestMethod("POST");
// 设定传送的内容类型是可序列化的java对象
// (如果不设此项,在传送序列化对象时,当WEB服务默认的不是这种类型时可能抛java.io.EOFException)
hconn.setRequestProperty("Content-type",
"application/x-java-serialized-object");
hconn.setRequestProperty("Connection", "Keep-Alive");
// http正文内,因此需要设为true, 默认情况下是false;
hconn.setDoOutput(true);
// Post 请求不能使用缓存
hconn.setUseCaches(false);
hconn.setRequestProperty("Content-Length", "" + postData.length());
//OutputStreamWriter out = new OutputStreamWriter(
//
hconn.getOutputStream(), "UTF-8");
//out.write(postData.toString());
//out.flush();
//out.close();
// 获取响应状态
if (hconn.getResponseCode() == HttpURLConnection.HTTP_OK) {
// System.out.println("OK");
} else {
System.out.println(hconn.getResponseCode());
}
// 获取响应内容体
String line, result = "";
BufferedReader in = new BufferedReader(new InputStreamReader(
hconn.getInputStream(), "UTF-8"));
while (null != (line = in.readLine())) {
result += line + "\n";
}
in.close();
return result;
// System.out.print(result);
} catch (Exception e) {
// TODO Auto-generated catch block
errlog(e);
e.printStackTrace();
}
return null;
}
//更新发送时间
updateSendTime();
URL url;
try {
//System.out.println(postUrl+"?"+postData.toString());
url = new URL(postUrl+"?"+postData.toString());
hconn = (HttpURLConnection) url.openConnection();
// 设置提交方式
hconn.setRequestMethod("POST");
// 设定传送的内容类型是可序列化的java对象
// (如果不设此项,在传送序列化对象时,当WEB服务默认的不是这种类型时可能抛java.io.EOFException)
hconn.setRequestProperty("Content-type",
"application/x-java-serialized-object");
hconn.setRequestProperty("Connection", "Keep-Alive");
// http正文内,因此需要设为true, 默认情况下是false;
hconn.setDoOutput(true);
// Post 请求不能使用缓存
hconn.setUseCaches(false);
hconn.setRequestProperty("Content-Length", "" + postData.length());
//OutputStreamWriter out = new OutputStreamWriter(
//
hconn.getOutputStream(), "UTF-8");
//out.write(postData.toString());
//out.flush();
//out.close();
// 获取响应状态
if (hconn.getResponseCode() == HttpURLConnection.HTTP_OK) {
// System.out.println("OK");
} else {
System.out.println(hconn.getResponseCode());
}
// 获取响应内容体
String line, result = "";
BufferedReader in = new BufferedReader(new InputStreamReader(
hconn.getInputStream(), "UTF-8"));
while (null != (line = in.readLine())) {
result += line + "\n";
}
in.close();
return result;
// System.out.print(result);
} catch (Exception e) {
// TODO Auto-generated catch block
errlog(e);
e.printStackTrace();
}
return null;
}
相关文章推荐
- 使用HttpURLConnection调用短信接口
- JAVA使用httpUrlConnection 调用http接口
- 远程接口调用HttpURLConnection,URL
- ASP通过http调用验证码短信接口源码
- 验证码短信接口VB6调用http源码
- SAP中用json数据格式调用http接口发送短信邮件案例
- 使用URL工具类调用webservice接口(soap)与http接口的实现方式
- SAP中用json数据格式调用http接口发送短信邮件案例
- restful接口客户端和服务端开发,HttpURLConnection,HttpClient,post ,get方式调用
- java HttpUrlConnection get和post 模拟请求 调用接口
- winForm调用HTTP短信接口
- winForm调用HTTP短信接口
- http请求,HttpClient,调用短信接口
- C# Http短信接口的调用~~~~~~~~
- 调用飞信网关服务器HTTP接口发送短信的ASP源码
- VB通过http调用验证码短信接口源码
- HttpUrlconnection POST提交 用于接口调用传参
- 短信http接口的java代码调用示例
- 采用HttpURLConnection方式调用第三方接口,接口的返回值经过unicode编码处理
- Delphi通过调用Http接口实现短信发送的功能