谁做过类似于短信平台的项目,我现在做的项目中有一个模块设计到短信互动,我们已经向移动开通了第三方接口,我现在的问题是如何把我获取的参数用post方法提交到移动给我们的url上,大家做过类似项目的给我发点源码上来,我参考下,谢谢,越详细越好
解决方案 »
- 表单提交 email值发生了变化 少了@
- 关于字符串置换的问题!!急!!求救!!
- s:checkbox 获取后台数据
- 关于Hibernate的findByExample的疑惑
- 数据库属性文件
- 要做到跨数据库,是复制分发?? 还是分布式查询??
- tomcat里数据源的问题
- String or binary date would be truncated一般是什么错误?
- 收邮件附件乱码问题
- 我做网站时要提供文件下载,用jsp怎么实现呢?
- 打算从ASP.NET转行到JSP了,请问有什么捷径和注意的吗?数据库和编程软件用什么搭配?
- SSH整合 初始化spring配置文件时报 Bean name must not be empty
http://hc.apache.org/httpclient-3.x/methods/post.html
package com.crayze.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import org.apache.log4j.Logger;
public class HttpClient{
private static Logger log = Logger.getLogger(HttpClient.class);
/**
* 功能: 向呼叫控制发送呼叫信息
* @param encode
* @param sparametersPOST 的参数
* @param curl呼叫控制的链接
* @param smethodhttp请求方法 GET OR POST
* @return*/
public static String sendPostRequest(String encode,String sparameters, String curl){
String strRtn = "-1";
URL url = null;
String str = null;
OutputStreamWriter os = null;
BufferedReader is = null;
HttpURLConnection httpConn = null;
try{
url = new URL(curl);
httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
httpConn.setRequestMethod("POST");
os = new OutputStreamWriter(httpConn.getOutputStream(), encode);
os.write(sparameters);
os.flush();
os.close();
is = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
while ((str = is.readLine()) != null){
strRtn = str;
}
is.close();
os = null;
is = null;
str = null;
httpConn.disconnect();
}
catch (MalformedURLException e){
strRtn = "malError";
e.printStackTrace();
}
catch (UnknownHostException unhostex){
log.debug("in requestUrl() UnknownHostException error: "+ unhostex.getMessage());
strRtn = "unknowError";
}
catch (IOException ex){
log.debug("in requestUrl() error: " + ex.toString());
strRtn = "ioError";
}
finally{
try{
if (os != null)
os.close();
if (is != null)
is.close();
}
catch (IOException e){
e.printStackTrace();
}
}
log.debug("strRtn is [" + strRtn + "]");
return strRtn;
}
/**
* @param encode
* @param sparameters
* @param curl
* @return
*/
public static String sendGetRequest(String encode,String sparameters, String curl){
String strRtn = "-1";
URL url = null;
String str = null;
BufferedReader is = null;
HttpURLConnection httpConn = null;
StringBuffer sb = null;
try{
sb = new StringBuffer(curl);
sb.append("?");
sb.append(sparameters);
url = new URL(sb.toString());
httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
httpConn.setRequestMethod("GET");
is = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
while ((str = is.readLine()) != null){
strRtn = str;
}
is.close();
is = null;
str = null;
httpConn.disconnect();
}
catch (MalformedURLException e){
strRtn = "malError";
e.printStackTrace();
}
catch (UnknownHostException unhostex){
log.debug("in requestUrl() UnknownHostException error: "+ unhostex.getMessage());
strRtn = "unknowError";
}
catch (IOException ex){
log.debug("in requestUrl() error: " + ex.toString());
strRtn = "ioError";
}
finally{
try
{
if (is != null)
is.close();
}
catch (IOException e){
e.printStackTrace();
}
}
log.debug("strRtn is [" + strRtn + "]");
return strRtn;
}
}
上面的是HttpClient类,下面的类是获取的一些数据,并把这些数据调用这个HttpClient类传出去,、package com.crayze.phonebox.sms;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import com.crayze.util.HttpClient;
import com.crayze.util.ManipulateXml;
public class Sms9588AdapterServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
private Logger log = Logger.getLogger(Sms9588AdapterServlet.class);
private String strLogicUrl = "";
// 成功发送
private static int SEND_OK = 0;
// 目前短信业务平台定义的错误代码都是>0的整数在这里防止和平台定义冲突可以用负整数定义
// 连接错误
private static int CONNECT_ERROR = -1000;
// IO异常
private static int IO_ERROR = -2000;
// 分析短信业务平台回应的错误
private static int WAPDM_ERROR = -3000;
// Initialize global variables
public void init(ServletConfig config) throws ServletException {
strLogicUrl = config.getInitParameter("logicurl");
}
// Process the HTTP Get request
public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
String strTemp = null;
String strRtn = null;
try {
Document doc = null;
doc = ManipulateXml.readXmlDocumentFromStream(request.getInputStream());
Element root = doc.getDocumentElement();
String Message = ManipulateXml.getElementValue(ManipulateXml.firstElementByName(root, "MESSAGE"));
String clientPhone = ManipulateXml.getElementValue(ManipulateXml.firstElementByName(root, "MSISDN"));
log.debug("before transfor Message Content is [ " + Message + "]");
// log.debug("Message Content is [ " + strTemp + "]");
log.debug("clientPhone is [ " + clientPhone + "]");
SmbppSendUnicodeMessage("", "4083MFBZ4083M0000", "", clientPhone,clientPhone, Message, 0, 0, 0, 0, 0, 0);
StringBuffer sb = new StringBuffer("");
// sb.append(strReqInitParam);
sb.append("clientPhone=");
sb.append(clientPhone);
sb.append("&subsPhone=");
// sb.append("0106432975-1049,13811258898");
sb.append("13811258898");
sb.append("&timeLen=3600");
// sb.append(strTimeLen);
sb.append("&ivrflowtype=121");
// sb.append(ivrflowtype);
log.debug("param is " + sb.toString());
log.debug("request url " + strLogicUrl);
// 发送呼叫请求
strRtn = HttpClient.sendPostRequest("GBK", sb.toString(),strLogicUrl);
log.debug("HttpClient rtn is: " + strRtn);
} catch (SAXException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
this.doPost(request, response);
}
private void SmbppSendUnicodeMessage(String bstrMoMessageID,String bstrBusinessCode, String bstrLongCode,
String bstrFeeMsisdn,String bstrDesMsisdn, String bstrMessageContent, int lTpPid,
int lTpUdhi, int lSendDate, int lSendTime, int lExpireDate,int lExpireTime) {
// POST的参数
String paramStr = "bstrMoMessageID=" + bstrMoMessageID
+ "&bstrBusinessCode=" + bstrBusinessCode + "&bstrLongCode="
+ bstrLongCode + "&bstrFeeMsisdn=" + bstrFeeMsisdn
+ "&bstrDesMsisdn=" + bstrDesMsisdn + "&bstrMessageContent="
+ bstrMessageContent + "&lTpPid=" + lTpPid + "&lTpUdhi="
+ lTpUdhi + "&lSendDate=" + lSendDate + "&lSendTime="
+ lSendTime + "&lExpireDate=" + lExpireDate + "&lExpireTime="
+ lExpireTime + "&username=4584&password=nvuhejidjk";
// 发送UnicodeMess的URL
String destURL = "http://59.151.7.69/SmbpHttpAgent/SmbpHttpAgent.asmx/SmbppSendUnicodeMessage";
// 调用向短信业务平台提交数据的方法
String rtn = null;
rtn = HttpClient.sendPostRequest("GBK", paramStr, destURL);
log.debug("send rtn is " + rtn);
public void destroy() {
}
}帮我看看有什么问题,谢谢
原文网址:http://blog.csdn.net/sunyujia/archive/2008/05/02/2362800.aspx楼主应该和对方沟通下.