public static int GET_Lua(IntPtr L) { string url = Api.lua_tostring(L, 1); string function = Api.lua_tostring(L, 2); string queryString = Api.lua_tostring(L, 3); LuaFunction complete = null; if (Api.lua_isfunction(L, 4)) { complete = (LuaFunction)lua.Lua.ValueAtInternal(L, 4); } var context = (WebRequest2.Context)lua.Lua.ObjectAtInternal(L, 5); WebRequest2.GET(new System.Uri(url), function, queryString, (s, resCode, payload, cookies, headers, localContext) => { if (complete != null) { if (s == WebExceptionStatus.Success && resCode == HttpStatusCode.OK) { complete.Invoke(true, payload); } else { complete.Invoke(false); } complete.Dispose(); } }, context); return(0); }
public RecaptchaResultModel CheckIt(string secret, string code) { var client = new WebRequest2(); var data = new Dictionary <string, string> { { "secret", secret }, { "response", code } }; var tokenResult = client.PostForm("https://www.google.com/recaptcha/api/siteverify", data); return(tokenResult.ParseJson <RecaptchaResultModel>()); }
public ResultModel AddMember(string firstName, string lastName, string email, int listId, TokenResult token) { var client = new WebRequest2(); var data = new Dictionary <string, string> { { "Email", email }, { "FirstName", firstName }, { "LastName", lastName }, { "ListId", listId.ToString() } }; var resultData = client.PostForm("https://api.mail2inbox.com/api/Member", data, token.access_token); return(resultData.ParseJson <ResultModel>()); }
public TokenResult GetToken(string userName, string password) { var client = new WebRequest2(); var data = new Dictionary <string, string> { { "grant_type", "password" }, { "username", userName }, { "password", password.ToBase64() } }; var tokenResult = client.PostForm("https://api.mail2inbox.com/token", data); return(tokenResult.ParseJson <TokenResult>()); }
public ResultModel SendMail(SendPostModel msg, TokenResult token) { var client = new WebRequest2(); var data = new Dictionary <string, string> { { "From", msg.From }, { "To", msg.To }, { "Reply", msg.Reply }, { "Cc", msg.Cc }, { "Bcc", msg.Bcc }, { "Subject", msg.Subject }, { "Body", msg.Body } }; var resultData = client.PostForm("https://api.mail2inbox.com/api/send", data, token.access_token); return(resultData.ParseJson <ResultModel>()); }
public string GetRealIp(HttpRequest request) { try { var client = new WebRequest2(); var response = client.GetUrl("http://checkip.dyndns.org", null); var a = response.Split(':'); var a2 = a[1].Substring(1); var a3 = a2.Split('<'); var a4 = a3[0]; return(a4 + " (" + GetIp(request) + ")"); } catch (Exception) { } var ip = request.HttpContext.Connection.RemoteIpAddress; return(ip.ToString()); }
public string PushToUser(string to, string title, string body, bool contentAvailable, bool mutableContent) { var client = new WebRequest2(); var msg = new OnePushUserModel { app_id = _appId, contents = new OnePushContent { en = body }, headings = new OnePushContent { en = title }, include_external_user_ids = new[] { to }, content_available = contentAvailable, mutable_content = mutableContent }; var tt = msg.ToJson(); return(client.PostJsonBasicAuth(Url, tt, _key)); }
public static int Download_Lua(IntPtr L) { string url = Api.lua_tostring(L, 1); string storePath = string.Empty; int index = 2; if (Api.lua_isstring(L, index)) { storePath = Api.lua_tostring(L, index); storePath = Path.Combine(Application.persistentDataPath, storePath); ++index; var dir = Path.GetDirectoryName(storePath); if (!Directory.Exists(dir)) { try { Directory.CreateDirectory(dir); } catch (Exception e) { Api.lua_pushstring(L, e.ToString()); return(1); } } } LuaFunction complete = null; if (Api.lua_isfunction(L, index)) { complete = (LuaFunction)lua.Lua.ValueAtInternal(L, index); } WebRequest2.Download(url, (data) => { if (string.IsNullOrEmpty(storePath)) { if (complete != null) { complete.Invoke(data); complete.Dispose(); } } else { if (data != null) { try { File.WriteAllBytes(storePath, data); if (complete != null) { complete.Invoke(storePath); complete.Dispose(); } } catch (Exception e) { if (complete != null) { complete.Invoke((object)null, e.ToString()); complete.Dispose(); } } } } }); return(0); }