Function Post(url,data)
dim Https
set Https=server.createobject("MSXML2.XMLHTTP")
Https.open "POST",url,false
Https.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
Https.send data
if Https.readystate=4 then
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write Https.responseBody
objstream.Position = 0
objstream.Type = 2
objstream.Charset = "gb2312"
Post = objstream.ReadText
objstream.Close
set objstream = nothing
set https=nothing
end if
End Function
dim target,post_data
userName = "帐号"
PassWord = "密码"
Mobile = "15574888434"
Content = "84192"
target = "http://service.winic.org:8813/Service.asmx/SendVoiceForCode?"
post_data = "userName="&userName&"&PassWord="&PassWord&"&Mobile="&Mobile&"&Code="&Content&"&DisPlayNbr=&vReplay="
response.Write(Post(target,post_data))
$randStr = str_shuffle('1234567890');
$code = substr($randStr,0,4);
$content = "你的验证码是:".$code."【中正云通信】";
$mobile = "手机号码";
function NewSms($mobile,$content){
$url="http://service.winic.org:8813/Service.asmx/SendVoiceForCode?";
$data = "userName=%s&PassWord=%s&Mobile=%s&Code=%s&DisPlayNbr=&vReplay=";
$id = '账号';
$pwd = '密码';
$to = $mobile;
$content = $content;
$rdata = sprintf($data, $id, $pwd, $to, $content);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$rdata);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
echo NewSms($mobile,$content);
private void button1_Click_1(object sender, EventArgs e)
{
string uid = t_uid.Text.Trim();
string pwd = t_pwd.Text.Trim();
string mob = t_mob.Text.Trim();
string msg = t_msg.Text.Trim();
url = "http://service.winic.org:8813/Service.asmx/SendVoiceForCode?";
data = "userName=" + uid + "&PassWord=" + pwd + "&Mobile=" + mob + "&Code=" + msg + "&DisPlayNbr=&vReplay=";
string backinfo = PostData(url, data);
vtag.Text = backinfo;
}
public static string PostData(string purl,string str){
try{
byte[] data = System.Text.Encoding.GetEncoding("GB2312").GetBytes(str);
// 准备请求
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(purl);
//设置超时
req.Timeout = 30000;
req.Method = "Post";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = data.Length;
Stream stream = req.GetRequestStream();
// 发送数据
stream.Write(data, 0, data.Length);
stream.Close();
HttpWebResponse rep = (HttpWebResponse)req.GetResponse();
Stream receiveStream = rep.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("UTF-8");
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader(receiveStream, encode);
Char[] read = new Char[256];
int count = readStream.Read(read, 0, 256);
StringBuilder sb = new StringBuilder("");
while (count > 0)
{
String readstr = new String(read, 0, count);
sb.Append(readstr);
count = readStream.Read(read, 0, 256);
}
rep.Close();
readStream.Close();
return sb.ToString();
}
catch (Exception ex)
{
return "posterror";
}
}
public static String HTTP_POST(String URL, String Data) throws Exception {
BufferedReader In = null;
PrintWriter Out = null;
HttpURLConnection HttpConn = null;
try {
URL url=new URL(URL);
HttpConn=(HttpURLConnection)url.openConnection();
HttpConn.setRequestMethod("POST");
HttpConn.setDoInput(true);
HttpConn.setDoOutput(true);
Out=new PrintWriter(HttpConn.getOutputStream());
Out.println(Data);
Out.flush();
if(HttpConn.getResponseCode() == HttpURLConnection.HTTP_OK){
StringBuffer content = new StringBuffer();
String tempStr = "";
In = new BufferedReader(new InputStreamReader(HttpConn.getInputStream()));
while((tempStr = In.readLine()) != null){
content.append(tempStr);
}
In.close();
return content.toString();
}
else
{
throw new Exception("HTTP_POST_ERROR_RETURN_STATUS:" + HttpConn.getResponseCode());
}
} catch (IOException e) {
e.printStackTrace();
}finally{
Out.close();
HttpConn.disconnect();
}
return null;
}
public static void main(String[] args) throws Exception{
String HTTP_BACK_MESSAGE = "";
url = "http://service.winic.org:8813/Service.asmx/SendVoiceForCode";
data = "userName=账号&PassWord=密码&Mobile=手机号码&Code=验证码&DisPlayNbr=&vReplay=";
HTTP_BACK_MESSAGE = HTTP_POST(url, data);
System.out.println(HTTP_BACK_MESSAGE);
}
protected void bntSendNote_Click(object sender, EventArgs e)
{
WebService.Service1 ws = new WebService.Service1();
txtResult.Text = ws.SendVoiceForCode(txt_userName, txt_PassWord, txt_Mobile,txt_Code,txt_DisPlayNbr,txt_vReplay);
}
// 注意引用 uses comobj
//_________________________________HTTP通信函数返回信息
function HTTPwebservice(url:string):string;
var
responseText: WideString;
xmlHttp: OLEVariant;
begin
try
xmlHttp:=CreateOleObject('Msxml2.XMLHTTP');
xmlHttp.open('GET',url,false);
xmlHttp.send();
responseText:=xmlHttp.responseText;
if xmlHttp.status='200' then
begin
HTTPwebservice:=responseText;
end;
xmlHttp := Unassigned;
except
exit;
end;
end;
//______________________________
//使用时调用即可
url:='http://service.winic.org:8813/Service.asmx/SendVoiceForCode?';
data:='userName=账号&PassWord=密码&Mobile=手机号码&Code=验证码&DisPlayNbr=&vReplay=';
bdata:=HTTPwebservice(url+data);
int basefd;
char *hostname = "service.winic.org:8813";
char *send_sms_uri = "/Service.asmx/SendVoiceForCode";
ssize_t http_post(char *page, char *poststr)
{
char sendline[MAXLINE + 1], recvline[MAXLINE + 1];
ssize_t n;
snprintf(sendline, MAXSUB,
"POST %s HTTP/1.0\r\n"
"Host: %s\r\n"
"Content-type: application/x-www-form-urlencoded\r\n"
"Content-length: %zu\r\n\r\n"
"%s", page, hostname, strlen(poststr), poststr);
write(basefd, sendline, strlen(sendline));
while ((n = read(basefd, recvline, MAXLINE)) > 0) {
recvline[n] = '\0';
printf("%s", recvline);
}
return n;
}
ssize_t send_sms(char *userName, char *PassWord, char *Mobile, char *Code, char *DisPlayNbr, char *vReplay)
{
char params[MAXPARAM + 1];
char *cp = params;
sprintf(cp,"userName=%s&PassWord=%s&Mobile=%s&Code=%s&DisPlayNbr=&vReplay=%s", userName, PassWord, Mobile, Code, DisPlayNbr, vReplay);
return http_post(send_sms_uri, cp);
}
int socked_connect(char *arg)
{
struct sockaddr_in their_addr = {0};
char buf[1024] = {0};
char rbuf[1024] = {0};
char pass[128] = {0};
struct hostent *host = NULL;
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd<0)
{
printf ("create the sockfd is failed\n");
return -1;
}
if((host = gethostbyname(arg))==NULL)
{
printf("Gethostname error, %s\n");
return -1;
}
memset(&their_addr, 0, sizeof(their_addr));
their_addr.sin_family = AF_INET;
their_addr.sin_port = htons(80);
their_addr.sin_addr = *((struct in_addr *)host->h_addr);
if(connect(sockfd,(struct sockaddr *)&their_addr, sizeof(struct sockaddr)) < 0)
{
close(sockfd);
return -1;
}
printf ("connect is success\n");
return sockfd;
}
int main(void)
{
struct sockaddr_in servaddr;
char str[50];
sockfd = socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_addr =*(hostname);
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(80);
inet_pton(AF_INET, str, &servaddr.sin_addr);
connect(sockfd, (SA *) & servaddr, sizeof(servaddr));
#endif
if((basefd= socked_connect(hostname))==-1)
{
printf("connect is failed\n");
return -1;
}
printf("basefd is =%d\n",basefd);
char *userName = "xx";
char *PassWord "xx";
char *Mobile ="13222334512";
char *Code "验证码是:1 2 3 4 5 6";
char *DisPlayNbr = "";
char *vReplay = "2";
send_sms(userName, PassWord, Mobile, Code, DisPlayNbr, vReplay);
printf("send the message is success\n");
close(basefd);
exit(0);
}