Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8064521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:23:33+00:00 2026-06-05T11:23:33+00:00

last time I posted a question on here everyone provided some great guidance on

  • 0

last time I posted a question on here everyone provided some great guidance on getting my problem solved. Move forward in time and here is another. I’m attempting to redo a small helper tool I have that checks URL’s and Files against VirusTotal to get some basic information. The code below works quite well but locks up the UI. I was told that I should look into Rx and am enjoying reading up on it but cannot seem to get my head wrapped around it. So now here is where the question comes in, what is the best way to design the following code to make it utilize Rx so that it is asynchronous and leaves my UI alone while it does it’s thing. VirusTotal also utilizes multilevel JSON for responses so if anyone has a nice way of integrating that into this that would even be better.

class Virustotal
{
    private string APIKey = "REMOVED";
    private string FileReportURL = "https://www.virustotal.com/vtapi/v2/file/report";
    private string URLReportURL = "http://www.virustotal.com/vtapi/v2/url/report";
    private string URLSubmitURL = "https://www.virustotal.com/vtapi/v2/url/scan";

    WebRequest theRequest;
    HttpWebResponse theResponse;
    ArrayList  theQueryData;

    public string GetFileReport(string checksum) // Gets latest report of file from VT using a hash (MD5 / SHA1 / SHA256)
    {
        this.WebPostRequest(this.FileReportURL);
        this.Add("resource", checksum);
        return this.GetResponse();
    }

    public string GetURLReport(string url) // Gets latest report of URL from VT
    {
        this.WebPostRequest(this.URLReportURL);
        this.Add("resource", url);
        this.Add("scan", "1"); //Automatically submits to VT if no result found
        return this.GetResponse();
    }

    public string SubmitURL(string url) // Submits URL to VT for insertion to scanning queue
    {
        this.WebPostRequest(this.URLSubmitURL);
        this.Add("url", url);
        return this.GetResponse();
    }

    public string SubmitFile() // Submits File to VT for insertion to scanning queue
    {
        // File Upload code needed
        return this.GetResponse();
    }

    private void WebPostRequest(string url)
    {
        theRequest = WebRequest.Create(url);
        theRequest.Method = "POST";
        theQueryData = new ArrayList();
        this.Add("apikey", APIKey);
    }

    private void Add(string key, string value)
    {
        theQueryData.Add(String.Format("{0}={1}", key, Uri.EscapeDataString(value)));
    }

    private string GetResponse()
    {
        // Set the encoding type
        theRequest.ContentType="application/x-www-form-urlencoded";

        // Build a string containing all the parameters
        string Parameters = String.Join("&",(String[]) theQueryData.ToArray(typeof(string)));
        theRequest.ContentLength = Parameters.Length;

        // We write the parameters into the request
        StreamWriter sw = new StreamWriter(theRequest.GetRequestStream());
        sw.Write(Parameters);
        sw.Close();

        // Execute the query
        theResponse =  (HttpWebResponse)theRequest.GetResponse();
        StreamReader sr = new StreamReader(theResponse.GetResponseStream());
        return sr.ReadToEnd();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:23:35+00:00Added an answer on June 5, 2026 at 11:23 am

    Your code is poorly written which makes it more difficult to make it asynchronous – primarily the three class-level variables. When coding in Rx you want to think “functional programming” and not “OOP” – so no class-level variables.

    So, what I’ve done is this – I’ve recoded the GetResponse method to encapsulate all of the state into a single call – and I’ve made it return IObservable<string> rather than just string.

    The public functions can now be written like this:

    public IObservable<string> GetFileReport(string checksum)
    {
        return this.GetResponse(this.FileReportURL,
            new Dictionary<string, string>() { { "resource", checksum }, });
    }
    
    public IObservable<string> GetURLReport(string url)
    {
        return this.GetResponse(this.URLReportURL,
            new Dictionary<string, string>()
                { { "resource", url }, { "scan", "1" }, });
    }
    
    public IObservable<string> SubmitURL(string url)
    {
        return this.GetResponse(this.URLSubmitURL,
            new Dictionary<string, string>() { { "url", url }, });
    }
    
    public IObservable<string> SubmitFile()
    {
        return this.GetResponse("UNKNOWNURL", new Dictionary<string, string>());
    }
    

    And GetResponse looks like this:

    private IObservable<string> GetResponse(
        string url,
        Dictionary<string, string> theQueryData)
    {
        return Observable.Start(() =>
        {
            var theRequest = WebRequest.Create(url);
            theRequest.Method = "POST";
            theRequest.ContentType="application/x-www-form-urlencoded";
    
            theQueryData.Add("apikey", APIKey);
    
            string Parameters = String.Join("&",
                theQueryData.Select(x =>
                    String.Format("{0}={1}", x.Key, x.Value)));
            theRequest.ContentLength = Parameters.Length;
    
            using (var sw = new StreamWriter(theRequest.GetRequestStream()))
            {
                sw.Write(Parameters);
                sw.Close();
            }
    
            using (var theResponse =  (HttpWebResponse)theRequest.GetResponse())
            {
                using (var sr = new StreamReader(theResponse.GetResponseStream()))
                {
                    return sr.ReadToEnd();
                }
            }
        });
    }
    

    I haven’t actually tested this – I don’t have the APIKEY for starters – but it should work OK. Let me know how you go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a great response the last time I posted here. I have the
I had much luck last time I submitted a question so here goes: I
I recently posted a question about getting last 3 results in table in the
Good day friends! I'm experiencing one huge problem here! First, I posted a question
In my last question I posted some sample code on how I was trying
After the you guys helped me out so gracefully last time, here is another
I have tables as posted in this question . •Measurements (MeasureID, Time, Distance, Value)
Based on another question I posted on here, I was able to get the
So last week I posted a problem for the ACM ICPC South East Regionals
The last time I did any serious Java coding was back around the turn

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.