一般处理程序代码
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string action = context.Request.QueryString["action"]; if (action == "get") { string url = "http://192.168.10.191:8078/recharge/getorder.ashx?"; string appid = context.Request.QueryString["app_id"]; string secretStr = context.Request.QueryString["secret_code"]; string phone = context.Request.QueryString["phone"]; string amount = context.Request.QueryString["amount"];
url += "app_id=" + appid + "&phone=" + phone + "&amount=" + amount + "&secret_code=" + secretStr + "";
string result = RequestGetUrl(url); if (result != "") { context.Response.Write(result); } else { context.Response.Write(result); } } if (action == "post") { string url = "http://192.168.10.191:8078/recharge/getorder.ashx?"; string appid = context.Request.QueryString["app_id"]; string secretStr = context.Request.QueryString["secret_code"]; string phone = context.Request.QueryString["phone"]; string amount = context.Request.QueryString["amount"]; string postData= "app_id=" + appid + "&phone=" + phone + "&amount=" + amount + "&secret_code=" + secretStr + ""; string result =RequestPostUrl(url,postData); if (result != "") { context.Response.Write(result); } else { context.Response.Write(result); } }
} #region Get方式请求 /// <summary> /// Get方式请求 /// </summary> /// <param name="url"></param> /// <returns></returns> public static string RequestGetUrl(string url) { try { WebRequest request = WebRequest.Create(url); WebResponse response = request.GetResponse(); Stream resStream = response.GetResponseStream(); StreamReader sr = new StreamReader(resStream, System.Text.Encoding.UTF8); String aaa = ""; aaa = sr.ReadToEnd(); resStream.Close(); sr.Close(); return aaa; } catch { return ""; }
} #endregion
#region RequestPostUrl post方式提交数据 public static string RequestPostUrl(string url, string content)//post方式向页面提交 { byte[] bs = Encoding.UTF8.GetBytes(content); string resultStream = null; HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded;charset=utf-8"; req.ContentLength = bs.Length;
req.Timeout = 20000; //设置发送内容 try { using (Stream reqStream = req.GetRequestStream()) { reqStream.Write(bs, 0, bs.Length); reqStream.Close(); reqStream.Dispose(); } } catch {
} try { WebResponse wr = req.GetResponse(); using (wr) {
//在这里对接收到的页面内容进行处理 Stream stream = wr.GetResponseStream(); StreamReader sr = new StreamReader(stream, Encoding.UTF8); resultStream = @sr.ReadToEnd(); } } catch (Exception e) { resultStream = "0";
} return resultStream;
} #endregion
js页面代码
<script type="text/javascript" language="javascript"> function sendGet() { var shoujihaoma = document.getElementById("Mobphone").value; var phone = md5(); var app_id = "2B3D396DBD874913BA0EBCF4E04E394A"; var qian = jine(); alert(shoujihaoma); alert(app_id); if(app_id!=""&&shoujihaoma!="" && shoujihaoma!="" && qian!="" && phone!=""){ $.ajax({ type: "GET", url: "GetAppkey.ashx", dataType: "text", data: {action:"get",app_id: app_id,phone:shoujihaoma,amount:qian,secret_code:phone}, success: function (msg) { document.getElementById("span1").innerText = msg; } }); } //location.href = "http://192.168.10.191:8078/recharge/getorder.ashx?app_id=" + sett + "&phone=" + shoujihaoma + "&amount=" + qian + "&secret_code=" + phone; } </script>
<script type="text/javascript" language="javascript"> function sendPost() { var shoujihaoma = document.getElementById("Mobphone").value; var phone = md5(); var app_id = "2B3D396DBD874913BA0EBCF4E04E394A"; var qian = jine(); alert(shoujihaoma); alert(app_id); if(app_id!=""&&shoujihaoma!="" && shoujihaoma!="" && qian!="" && phone!=""){ $.ajax({ type: "get", url: "GetAppkey.ashx", dataType: "text", data: {action:"post",app_id: app_id,phone:shoujihaoma,amount:qian,secret_code:phone}, success: function (msg) { document.getElementById("span1").innerText = msg; } }); } //location.href = "http://192.168.10.191:8078/recharge/getorder.ashx?app_id=" + sett + "&phone=" + shoujihaoma + "&amount=" + qian + "&secret_code=" + phone; } </script>