Archived Forum Post

Index of archived forum posts


After HTTP asynchronous task completed, how to get the Response object?

Apr 26 '16 at 15:33

I’m calling PTextAsync.

Set task = http.PTextAsync("POST", sURL, sPostData, "UTF-8", "plain/text", 0, 0)

After the task has completed, how do I get to the response object? i.e. resp.StatusCode, resp.BodyStr


Each type of Chilkat object that can possibly be the return value of a synchronous method call will have a method named LoadTaskResult.

For example, when http.PText is called synchronously,it would return an HttpResponse object. When called asynchronously (i.e. http.PTextAsync) it returns a Task object. When the task completes, the task object (internally) has a reference to the returned HttpResponse object.

Chilkat could have designed the software so that an app would get the returned object via a call to the Task object. For example, something like (in pseudo-code)

response = task.GetHttpResponseObject();   // This is NOT what Chilkat does..
This would be most straightforward, but would cause internal linkage across Chilkat classes, and for various reasons it's best to keep unrelated internal code from referencing each other.

The chosen solution is a little more roundabout. To get the returned object (such as the HttpResponse object), your app creates a new instance of the object and then calls LoadTask result. For example, in VB6:

Dim response As New ChilkatHttpResponse
success = response.LoadTaskResult(task)
Now you have a response object that's been loaded with the response object returned asynchronously in the background thread.


It appears to be working, although success is 0, I expected 1. The response code: 200, bodystr is fine.

Dim response As New ChilkatHttpResponse
success = response.LoadTaskResult(task)
If (success <> 1) Then
    MsgBox "success?: " & success & " - " & http.LastErrorText
End If

Here is the log:

    DllDate: Mar 11 2016
    UnlockPrefix: xxxxxxxxx
    Username: xxx-PC-00201:xxxxx
    Architecture: Little Endian; 32-bit
    Language: ActiveX
    VerboseLogging: 0
                startLine: POST /net2.0/Login/login/LoginMenu.aspx HTTP/1.1
              Not auto-adding cookies.
              sendCookies: 1
            domain: xxxxxxxx
            port: 80
            ssl: 0
              Opening connection directly to HTTP server.
              httpHostname: xxx-pc-00201
              httpPort: 80
              ssl: 0
              HTTP connection succeeded.
            connectTime: Elapsed time: 0 millisec
              sendHeaderElapsedMs: 16
            statusCode: 200
            statusText: OK
              contentLength: 53620
          success: 1
        success: 1


Thanks! I remember this problem and thought it was fixed. I'll have a look -- maybe the error is specific to the ActiveX..


I fixed the problem and if you need, I can provide a pre-release. Otherwise, it will be in the next version released. A workaround would be to check the response.StatusCode property after calling LoadTaskResult. If the StatusCode equals 0, then the response was not loaded.