login about faq

I've search for samples, and in forums and documentation, but nothing mentions how to use Chilkat http asynchronously.

I've tried synchronously using QuickGet and confirm that my endpoint returns a response.

I debug the below code and confirm that a background Task is running and that it does notice there is an end and a http response 200. but none of my attempts to get the bgResultstring have been successful.

I set up HttpEndReceiveEventHandler, I've tried a horrible WHILE loop (sigh!) even.


simple version of code below:

class Program
{
    public static void Main(string[] args)
    {

    using (var chillkatHttpBgClient = new Chilkat.Http())
    {
        if (!chillkatHttpBgClient.IsUnlocked()) chillkatHttpBgClient.UnlockComponent(chillkatKey);
        chillkatHttpBgClient.UseBgThread = true;
        chillkatHttpBgClient.OnHttpEndReceive += new Chilkat.Http.HttpEndReceiveEventHandler(HttpEndReceiveEventHandlerEvent);

        var bgHttpResponseByteArray = chillkatHttpBgClient.QuickGet(requestUri);
        Console.WriteLine("Press enter to continue.");
        Console.ReadLine();
        chillkatHttpBgClient.OnHttpEndReceive -= new Chilkat.Http.HttpEndReceiveEventHandler(HttpEndReceiveEventHandlerEvent);
    }
}
public void HttpEndReceiveEventHandlerEvent(object response, Chilkat.StatusEventArgs status)
{
    Console.WriteLine("response: " + response.ToString());
    string httpResponseString = (string)response;
    Console.WriteLine("return status success: " + status.Success.ToString());
    Console.WriteLine("return value: " + httpResponseString);
}

class Program
{
public static void Main(string[] args)
{
    //content removed ....
    using (var chillkatHttpBgClient = new Chilkat.Http())
        {
            //for longer calls
            if (!chillkatHttpBgClient.IsUnlocked()) chillkatHttpBgClient.UnlockComponent(chillkatKey);
            chillkatHttpBgClient.KeepEventLog = true;
            chillkatHttpBgClient.VerboseLogging = true;
            chillkatHttpBgClient.ClearBgEventLog();

            chillkatHttpBgClient.UseBgThread = true;
            chillkatHttpBgClient.AllowGzip = true;
            chillkatHttpBgClient.Accept = "text/xml";

            if (!chillkatHttpBgClient.SetSslClientCertPfx(pfxFilename: pfxFilePath, pfxPassword: pfxPassword))
                throw new Exception("pfxError:" + chillkatHttpBgClient.LastErrorText);

            chillkatHttpBgClient.OnHttpEndReceive += new Chilkat.Http.HttpEndReceiveEventHandler(HttpEndReceiveEventHandlerEvent);

            var bgHttpResponseByteArray = chillkatHttpBgClient.QuickGet(requestUri);ient.LastErrorText);

            while(chillkatHttpBgClient.BgTaskRunning)
            {
                Console.WriteLine("##############################");
                int logCount = chillkatHttpBgClient.EventLogCount;
                if (logCount > 0)
                {
                    for (int logName = 0; logName < logCount; logName++)
                    {
                        Console.WriteLine("Log:{0}",logName.ToString());
                        //Console.WriteLine("{0}:{1}",
                        //  chillkatHttpBgClient.EventLogName(logName),
                        //  chillkatHttpBgClient.EventLogValue(logName));
                    }
                }
                chillkatHttpBgClient.ClearBgEventLog();
                Console.WriteLine("-");
            }

            Console.WriteLine("LastStatus: " + chillkatHttpBgClient.LastStatus);
            Console.WriteLine("LastResponseHeader: " + chillkatHttpBgClient.LastResponseHeader);
            Console.WriteLine("ResponseTxt: " + chillkatHttpBgClient.BgResultString);

            using (Chilkat.HttpResponse bankStreamResponse1 = chillkatHttpBgClient.BgResponseObject())
            {
                if (bankStreamResponse1 == null)
                    Console.WriteLine("BgResponseObject empty");
                else
                    Console.WriteLine("bankStreamResponse1 value: " + bankStreamResponse1.BodyStr);
            }
            Console.WriteLine("Press enter to continue.");
            Console.ReadLine();
            chillkatHttpBgClient.OnHttpEndReceive -= new Chilkat.Http.HttpEndReceiveEventHandler(HttpEndReceiveEventHandlerEvent);
            Console.WriteLine("OnHttpEndReceive unsubscribed");
        }

        using (var httpReq = new Chilkat.HttpRequest())
        {
            httpReq.AddHeader("Host", "www.example.com");
            httpReq.SetFromUrl("");
        }
    }

    public void HttpEndReceiveEventHandlerEvent(object response, Chilkat.StatusEventArgs status)
    {
        Console.WriteLine("response: " + response.ToString());
        string httpResponseString = (string)response;
        Console.WriteLine("return status success: " + status.Success.ToString());
        Console.WriteLine("return status: " + status.ToString());
        Console.WriteLine("return value: " + httpResponseString);
    }
       }

asked Oct 31 '14 at 05:16

Robert%20PM's gravatar image

Robert PM
111

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×186
×2

Asked: Oct 31 '14 at 05:16

Seen: 835 times

Last updated: Oct 31 '14 at 05:16

powered by OSQA