Archived Forum Post

Index of archived forum posts

Question:

C# http QuickGetStr - Is there a "best practice" usage?

Jun 16 '12 at 18:22

Hi. I have a coding question.

Chilkat.Http rthttp = new Chilkat.Http();
for (int lp1 = 0; lp1 < numurls; lp1++)
{
   string url = urllist[lp1];
   string s1 = rthttp.QuickGetStr(url);
   int i1 = rthttp.LastStatus
}

Eventually .LastStatus will return something other than 200 but the website is fine.

This problem never occurred until I had the same domain name in urllist[] more than once.

When I move "Chilkat.Http rthttp = new Chilkat.Http();" the problem goes away as follows.

for (int lp1 = 0; lp1 < numurls; lp1++)
 {
    string url = urllist[lp1];
    Chilkat.Http rthttp = new Chilkat.Http();
    string s1 = rthttp.QuickGetStr(url);
    int i1 = rthttp.LastStatus
 }

I am a bit of a novice programmer when it comes to all this and was wondering if there are some sort of "best practice" or standards I am missing. Should I always create a new instance in this case?

I debugged this problem surprisingly quickly (at least to me it was quickly), but I am getting into more and more complex coding and want to minimize needless debug time as much as possible. Any suggestions are welcome.

Thanks!


Answer

Examine the contents of the rthttp.LastErrorText after calling QuickGetStr. Make sure to get the LastErrorText before accessing the LastStatus property, otherwise the LastErrorText may be overwritten by the property access. The LastErrorText should provide more detailed information.

Also, one of the first lines of information in the LastErrorText is the "DllDate". If it is older than the latest version, which at the time of this post is approx. April 2012, then first download and use the very latest version of the Chilkat component.


Answer

I am using your LastErrorText suggestion now and in the future. The dll was up to date.

The http errors I had turned out to be a symptom, not the cause. Turned out to be StringArray I reloaded from text several times. I inserted a .clear and I am good in good shape now.

Thank you for the fast response!


Answer

Followup question. Was wondering about garbage collection . . . The "using" statement in C# is for IDisposable objects. Does that apply to Chilkat.http?