Archived Forum Post

Index of archived forum posts

Question:

ChilkatHTTP ActiveX 9.3.x cyrilic chars problem

Sep 06 '12 at 04:34

I try to implement RESTful server interaction from VB6 application. Server response in Windows-1251 encoding, and HTTP status code point to result of operation (e.g. 401 - bad login, 404 - not found, 200 - ok), and some of response headers contain detailed explanation on possible errors (in case of 401, 404 etc).

First I try to use: resultString = http.QuickGetStr() But all cyrilic (Windows-1251 specific) chars are stripped from resultString. If I see http log file it contains correct response body. * NOTE: ChilkatHTTP ActiveX 2.8.x return correct data!

Second I try to use: set httpResponse = http.SynchronousRequest() In this case httpResponse.bodyStr contains correct data with cyrilic chars. But when http response code is not 200, httpResponse is set to Nothing and there is no way to get http code and http headers. Because http.LastHeader and http.LastStatus are empty. Only http log file contains code and headers.

How to solve my problem using ChilkatHTTP ActiveX 9.3.x ?


Answer

Please provide two snippets of code using the actual URL's so that I may reproduce the problem. The 1st snippet should be for the QuickGetStr problem, and the 2nd for the SynchronousRequest problem. (Make sure to provide an example where the HTTP status code returned will be something other than 200.)


Answer

I write some test server scripts for you. And found some intresting details.

If server response is like that (cyrillic chars in <description> tag)

HTTP/1.1 200 OK
Server: nginx/0.7.63
Date: Mon, 03 Sep 2012 10:06:38 GMT
Content-Type: application/xml; charset=windows-1251
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/5.2.11-1

1f44
<?xml version="1.0" encoding="WINDOWS-1251" ?>
<uedb>
<record uid="293200338">
<agent_phone_id>293200338</agent_phone_id>
<description>БелИнвестНедвижимость</description>
<deleted>0</deleted>
<last_modification>2012-08-31 14:15:30</last_modification>
</record> 
...

The result of QuickGetStr() is (note on description tag):

<?xml version="1.0" encoding="WINDOWS-1251" ?>
<uedb>
<record uid="293200338">
<agent_phone_id>293200338</agent_phone_id>
<description></description>
<deleted>0</deleted>
<last_modification>2012-08-31 14:15:30</last_modification>
</record> 
...

But when resopnse header "Content-Type" is like that:

Content-Type: text/xml; charset=windows-1251

Method QuickGetStr() return correct string. When encoding of response is UTF-8 - QuickGetStr() works with in both case. Also note version 2.8.x return correct string as well in case of "application/xml; charset=windows-1251"

You can test it by yourself:

Dim http As New ChilkatHttp
Dim strResult As String

Call http.UnlockComponent("Trial")

http.SessionLogFilename = CurrentFolder & ".http_session.log"
http.AcceptCharset = "windows-1251"
http.AcceptLanguage = "ru"
http.AllowGzip = 0

' not working correctly
strResult = http.QuickGetStr("http://realt.by/api/test-cp1251-application.php")
' but it works!
' strResult = http.QuickGetStr("http://realt.by/api/test-cp1251-text.php")
Debug.Print strResult

The problem with SynchronousRequest() is not any usefull information available on HTTP object, and resonse object is also is NULL. For example I request GET http://realt.by/api/test-404.php with SynchronousRequest().

Content of http://realt.by/api/test-404.php is:

header ('HTTP/1.1 404 NOT FOUND');
header('Cache-Control: no-cache');
header('Pragma: no-cache');
header('X-UEDB-Server: 1');
header('Error-Text: Just for test. Usualy here is detailed explanation of the error!');

I need to know that X-UEDB-Server header exists and what is content of Error-Text header. But SynchronousRequest() returns Nothing - as like as fatal error has occured.


Answer

Dmitry,

Thanks for the information. If the Content-Type of an HTTP response is "text/*", then Chilkat will interpret the bytes according to the "charset" attribute specified in the Content-Type header. When the Content-Type is "application/xml", the component is not paying attention to the "charset" attribute in the Content-Type header. I will make a fix to correct this situation. When a new build is ready, I'll post the download link here. (Hopefully by tomorrow)

Best Regards, Matt


Answer

This new build fixes the problem: http://www.chilkatsoft.com/preRelease/ChilkatHttp.zip


Answer

Thank you!

What about my second question about result of SynchronousRequest()?

I need correctly process different RESTful response http codes, and not only for GET method. Now, for example, i need to use two different methods for nearly same operations:

If I shall be able to use SynchronousRequest() for every operation (POST/PUT/GET/DELETE) my code will much more clear and server error processing will be in one place for every method.


Answer

This new build fixes the SynchronousRequest problem: http://www.chilkatsoft.com/preRelease/ChilkatHttp.zip

Any Chilkat HTTP method that returns a ChilkatHttpResponse object should return the object if the response is received, regardless of the value of the HTTP response status. The only reason a NULL should be returned is if the response could not be received (because of a disconnection, timeout, etc.)


Answer

Thank you again! I expect such behaviour from SynchronousRequest() when I first time read yours documentation. I'll test it today.

PS: Small note documentation. Your ActiveX library methods never return NULL value! Some methods can return Nothing, other return "" (vbNullString) on error.


Answer

Thank you again!

I expect such behaviour from SynchronousRequest() when I first time read yours documentation. I'll test it today.

PS: Small note documentation. Your ActiveX library methods never return NULL value! Some methods can return Nothing, other return "" (vbNullString) on error. Returned vbNullString also causes difficulties with determination of errors, because not all responses have body (even "200" responses) and in that case only HTTP response code is usefull (or may be some extra response headers).


Answer

I checked and found both bug are fixed.