public static void SendRequest() { Chilkat.HttpRequest req = new Chilkat.HttpRequest(); req.HttpVerb = "POST"; req.Path = @"/submission"; req.ContentType = "multipart/form-data"; req.AddHeader("Connection", "keep-alive"); req.AddHeader("User-Agent", "Mozilla/5.0"); req.AddHeader("Accept", @"*/*"); req.AddParam("name", "khanhtv0112"); req.AddParam("email", "*****@*****.**"); req.AddParam("title", "VidMate"); req.AddParam("category", "22"); req.AddParam("platform", "7"); req.AddParam("developer", "asd"); req.AddParam("url", @"https://apkpure.com/vidmate-downloader-hd-live-tv/com.nemo.vidmate/download?from=details"); req.AddParam("license", "asda"); req.AddParam("file_size", "sdas"); req.AddParam("detailed_description", "dasdfsdfsd"); string pathToFileOnDisk = "D:\\Projects\\3DLUT_mobile.png"; bool success = req.AddFileForUpload("image", pathToFileOnDisk); if (success != true) { Debug.WriteLine(req.LastErrorText); return; } Chilkat.Http http = new Chilkat.Http(); Chilkat.HttpResponse resp = http.SynchronousRequest("ahihisoftware.com", 443, true, req); if (http.LastMethodSuccess != true) { Debug.WriteLine(http.LastErrorText); return; } Debug.WriteLine("HTTP response status: " + Convert.ToString(resp.StatusCode)); string htmlStr = resp.BodyStr; Debug.WriteLine("Received:"); Debug.WriteLine(htmlStr); }
public bool doLogin(string username, string password) { this.username = username; this.password = password; if (!Directory.Exists(@"sessions\" + username)) { DirectoryInfo di = Directory.CreateDirectory(@"sessions\" + username); } File.Delete(@"sessions\" + username + @"\httpSessionLog.txt"); this.http.SessionLogFilename = @"sessions\" + username + @"\httpSessionLog.txt"; this.http.CookieDir = @"sessions\" + username; this.http.SetCookieXml(this.twitterHost, this.http.GetCookieXml(this.twitterHost) ); this.http.SendCookies = true; this.http.SaveCookies = true; if (!this.getAuthenticityToken()) return false; if (this.is_loggedin) return true; Console.WriteLine("Logging in....."); // Build an HTTP POST request to login this.req.RemoveAllParams(); this.req.UsePost(); this.req.Path = this.twitterLoginPath; //add params this.req.AddParam("session[username_or_email]", username); this.req.AddParam("session[password]", password); this.req.AddParam("authenticity_token", this.authenticity_token); this.req.AddParam("scribe_log", ""); this.req.AddParam("redirect_after_login", "/" + username); this.req.AddHeader("Referer", this.twitterMainUrl); // Send the HTTP POST and get the response. Note: This is a blocking call. // The method does not return until the full HTTP response is received. this.resp = this.http.SynchronousRequest(this.twitterHost, this.port, this.use_ssl, this.req); if (this.resp == null) { Console.WriteLine("ERROR: " + this.http.LastErrorText + "\n"); return false; } // Is this a 302 redirect? if (this.resp.StatusCode == 302 || this.resp.StatusCode == 200) { // Get the redirect URL: string redirectUrl = resp.GetHeaderField("location"); string html = String.Empty; //Console.WriteLine(resp.Header); //Console.WriteLine("Location: " + redirectUrl); if (redirectUrl != null && redirectUrl != String.Empty) { if ( redirectUrl.Contains("https://twitter.com/login/error") || redirectUrl.Contains("https://twitter.com/login/captcha") ) { return false; } html = http.QuickGetStr(redirectUrl); } else { html = this.resp.BodyStr; } //this.getAuthenticityToken(html); } else { //Console.WriteLine("ERROR: " + this.resp.BodyStr + "\n"); Console.WriteLine("ERROR: " + this.resp.StatusCode); return false; } this.is_loggedin = true; return true; }
public bool postTweet(string status, string reply_id) { if ( ! this.is_loggedin ) return false; Console.WriteLine("Posting message....."); // Build an HTTP POST request to login this.req.RemoveAllParams(); this.req.UsePost(); this.req.Path = this.twitterPostUrl; //add params this.req.AddParam("authenticity_token", this.authenticity_token); this.req.AddParam("place_id", ""); this.req.AddParam("status", status); if(reply_id != "" && reply_id != String.Empty) this.req.AddParam("in_reply_to_status_id", reply_id); this.req.AddHeader("Referer", this.twitterMainUrl); // Send the HTTP POST and get the response. Note: This is a blocking call. // The method does not return until the full HTTP response is received. this.resp = this.http.SynchronousRequest(this.twitterHost, this.port, this.use_ssl, this.req); if (this.resp == null) { Console.WriteLine("ERROR: " + this.http.LastErrorText + "\n"); return false; } // Is this a 200 if (this.resp.StatusCode != 200) { Console.WriteLine("ERROR: " + this.resp.StatusCode + "\n"); this.is_loggedin = false; return false; } return true; }