//public string POST_Message2(string sendURL, string message, string user, string pwd) //{ // //XMLHTTP xh = new XMLHTTP(); // XMLHTTP XML_HTTP = new XMLHTTP(); // XML_HTTP.open("POST", sendURL, false, user, pwd); // XML_HTTP.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); // XML_HTTP.setRequestHeader("SOAPAction", ""); // try{ // XML_HTTP.send(message); // } // catch (Exception e) // { // //return e.Message; // string errorText = e.Message.TrimEnd(new char[] { '\n', '\r' }); // throw new NetworkInterface_POSTException(errorText); // } // return XML_HTTP.responseText; //} public string POST_Message(int timeout_ms, string sendURL, string message, string user, string pwd) { MSXML2.ServerXMLHTTP xh = new ServerXMLHTTP(); //MSXML2.ServerXMLHTTP xh = new ServerXMLHTTP(); // set the timeouts xh.setTimeouts(timeout_ms, timeout_ms, timeout_ms, timeout_ms); Console.WriteLine("Sending request..."); xh.open("POST", sendURL, false, user, pwd); //xh.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xh.setRequestHeader("Content-Type", "application/soap+xml; charset=utf-8"); // SOAP Version 1.2 Part 2: Adjuncts (Second Edition) xh.setOption(SERVERXMLHTTP_OPTION.SXH_OPTION_SELECT_CLIENT_SSL_CERT, ""); try { xh.send(message); } catch (Exception e) { string errorText = e.Message.TrimEnd(new char[] { '\n', '\r' }); throw new NetworkInterface_POSTException(errorText); } if (xh.status == 401) { throw new NetworkInterface_POSTException("Error - " + xh.status.ToString() + " Username or Password not correct" + xh.statusText); } return(xh.responseText); }
/// <summary> /// 查询接口(返回字符串) /// </summary> /// <param name="jsonurl">查询地址</param> /// <param name="querystr">查询字符串</param> /// <param name="responsejson">返回数据</param> /// <param name="errmsg">错误信息</param> /// <returns></returns> public static bool QueryJson(string jsonurl, string querystr, out string responsejson, out string errmsg) { #region ServerXMLHTTP xmlhttp = new ServerXMLHTTP(); errmsg = ""; responsejson = ""; try { xmlhttp.open("POST", jsonurl, false, null, null); //xmlhttp.setRequestHeader("Content-Type", "text/xml;charset=utf-8"); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlhttp.send(querystr); if (xmlhttp.readyState == 4) { if (xmlhttp.responseText.Trim() != "") { responsejson = xmlhttp.responseText; } else { responsejson = ""; errmsg = "ErrEmpty"; } } } catch { errmsg = "ErrConnect"; } finally { xmlhttp.abort(); } if (errmsg != "") { Tools.SendeMail("", "*****@*****.**", "hbe json error", errmsg, true, Encoding.UTF8); return(false); } else { return(true); } #endregion }
protected void Button1_Click(object sender, EventArgs e) { //load xml templet XmlDocument usg = new XmlDocument(); var templet_path = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "templet.xml"); usg.Load(templet_path); //Update xml node. XmlNode root = usg.DocumentElement; root.FirstChild.SelectSingleNode("USER_NAME").InnerText = "Test_User"; //Send message //Using ServerXMLHTTP insted of var client = new ServerXMLHTTP(); client.open("POST", @"http://yourserveraddress.com/", false, null, null); client.send(usg.InnerXml); //Get response Response.Write(client.responseText); }
public static string GetSinaValue(string url, string sendData) { ServerXMLHTTP xmlhttp = new ServerXMLHTTP(); string errmsg = ""; string responsejson = ""; string jsonurl = url; try { xmlhttp.open("POST", jsonurl, false, null, null); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlhttp.send(sendData); if (xmlhttp.readyState == 4) { if (xmlhttp.responseText.Trim() != "") { responsejson = xmlhttp.responseText; } else { responsejson = ""; errmsg = "ErrEmpty"; } } } catch { errmsg = "ErrConnect"; } finally { xmlhttp.abort(); } if (errmsg != "") { return(errmsg); } else { return(responsejson); } }
public static string GetTranslate(string textToTranslate, string translateTo) { var translateFrom = "en"; string URL = $"https://translate.google.com/m?hl={translateFrom}&sl={translateFrom}&tl={translateTo}&ie=UTF-8&prev=_m&q={textToTranslate}"; //string URL = $"https://translate.google.com/m?hl={translateFrom}&sl={translateFrom}&tl={translateTo}&ie=UTF-8&prev=_m&q={textToTranslate}"; ServerXMLHTTP srv = new ServerXMLHTTP(); srv.open("GET", URL, false, null, null); srv.send(""); GetTranslateWebRequest(textToTranslate); if (srv.status == 200) { string markupResponse; markupResponse = srv.responseText; return(RegexExecute(markupResponse, "class=\\\"result-container\\\">(.+?)</div>")); } return(string.Empty); }
//Для PayPal IPN не забыть изменить адрес без sandbox!!! public void MakePayPalOrderVerification() { string Receiver_email = ""; string Payment_status = ""; string Payer_id = ""; string Payment_amount; string str = ""; str = Request.Form + "&cmd=_notify-validate"; ServerXMLHTTP srv = new ServerXMLHTTP(); try { //srv.open("POST", @"https://www.sandbox.paypal.com/cgi-bin/webscr", false, null, null); srv.open("POST", @"https://www.paypal.com/cgi-bin/webscr", false, null, null); srv.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); srv.send(str); Receiver_email = Request.Form["receiver_email"].ToString(); Payer_id = Request.Form["payer_id"].ToString(); Payment_status = Request.Form["payment_status"].ToString(); Payment_date = Request.Form["payment_date"].ToString(); Payer_email = Request.Form["payer_email"].ToString(); Payment_amount = Request.Form["mc_gross"].ToString(); First_name = Request.Form["first_name"].ToString(); Last_name = Request.Form["last_name"].ToString(); Address_country = Request.Form["address_country"].ToString(); Address_country_code = Request.Form["address_country_code"].ToString(); Address_zip = Request.Form["address_zip"].ToString(); Address_state = Request.Form["address_state"].ToString(); Address_city = Request.Form["address_city"].ToString(); Address_street = Request.Form["address_street"].ToString(); Txn_id = Request.Form["txn_id"].ToString(); if (srv.status != 200) //HTTP error handling //отправка email мне { SendMail("*****@*****.**", "*****@*****.**", "Ошибка 200 - платёж не прошёл", "Error_200"); } else if (srv.responseText == "VERIFIED") { if (Payment_status == "Completed") //check that Payment_status=Completed { //insert into DB значений db = new AvonessaDBEntities(); var i = (db.sp_InsertDataFromPayPal_0(First_name + " " + Last_name, Payer_email, Address_country, Address_zip, Address_country_code, Address_state, Address_city, Address_street, Payer_id, Payment_date, Txn_id)).SingleOrDefault(); //отправляем оповещения SendMail("*****@*****.**", "*****@*****.**", "Оплачено покупателем avonessa.com", "ToUs", i.Value.ToString()); SendMail("*****@*****.**", Payer_email, "", "ToBuyer", i.Value.ToString(), Address_country_code); } if (Receiver_email != "*****@*****.**") //check that Receiver_email is your Primary PayPal [email protected] { SendMail("*****@*****.**", "*****@*****.**", "IPN is hacked", "IPN_IsHacked"); } } else if (srv.responseText == "INVALID") { SendMail("*****@*****.**", "*****@*****.**", "IPN is hacked, maybe", "responseText_INVALID"); } else { SendMail("*****@*****.**", "*****@*****.**", "Unknown error", "Unknown_error"); } } finally { IDisposable disposable = srv as IDisposable; if (disposable != null) { disposable.Dispose(); } } }
protected void Page_Load(object sender, EventArgs e) { string url = @"http://autoever.hyundai.net/Webservices/SSO/SitemapWS.asmx"; string enccode = Request.Params["Encode"]; string companycode = Request.Params["CompanyCode"]; string strHKMCENC_ID = "RIDS"; string param = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body><GetPlainText xmlns=\"http://tempuri.org/\">" + "<strEncID>" + strHKMCENC_ID + "</strEncID>" + "<strCompanyCode>" + companycode + "</strCompanyCode>" + "<strEncText>" + enccode + "</strEncText>" + "</GetPlainText></soap:Body></soap:Envelope>"; System.Diagnostics.Debug.WriteLine("----------22"); ServerXMLHTTP srv = new ServerXMLHTTP(); srv.open("POST", url, false, null, null); srv.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); srv.setRequestHeader("SOAPAction", "http://tempuri.org/GetPlainText"); srv.send(param); Response.Clear(); string __res__ = srv.responseText; bool isLogin = false; try{ int val1 = __res__.IndexOf("<GetPlainTextResult>"); int val2 = __res__.IndexOf("</GetPlainTextResult>"); if (val1 <= 0 || val2 <= 0) { return; } string result = __res__.Substring(val1, (val2 - val1)); string[] token = System.Text.RegularExpressions.Regex.Split(result, "___"); for (int i = 0; i < token.Length; i++) { string[] value = System.Text.RegularExpressions.Regex.Split(token[i], "\\|\\|"); Session[value[0]] = value[1]; if ("User_ID".EndsWith(value[0])) { //Session["USERID"] = value[1]; string user = value[1]; // 그리고 사번.. OraDB DB = new OraDB(); DB.Connect(); try { string user_name = ""; string dept_code = ""; string login_sql = "select * from tb_person where user_id = '" + user + "'"; string object_id = DB.GetQueryResult <string>(login_sql, delegate(OracleDataReader reader) { string val = reader[0].ToString(); user_name = reader[1].ToString(); dept_code = reader[3].ToString(); return(val); }); if (object_id == null || "".Equals(object_id)) { isLogin = false; } else { Session["USERID"] = object_id; Session["USERNAME"] = user_name; Session["DEPTCODE"] = dept_code; isLogin = true; } DB.Close(); } catch (Exception eee) { System.Diagnostics.Debug.WriteLine(eee.Message); isLogin = false; } finally { DB.Close(); } } /* * if ("Dept_Code".EndsWith(value[0])) * { * Session["DEPTCODE"] = value[1]; * } * * if ("User_Name".EndsWith(value[0])) * { * Session["USERNAME"] = value[1]; * } */ } }catch (Exception ex) { Response.Write(ex.Message); } if (isLogin == false) { Response.Clear(); string res = "<script>alert('Access Dinied....');</script>"; Response.Write(res); return; } Response.Clear(); string res1 = "<script>this.location.href='/extjs/top.html';</script>"; Response.Write(res1); return; }