login about faq

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 ?

asked Aug 31 '12 at 06:55

Dmitry's gravatar image

Dmitry
1111


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.)

link

answered Aug 31 '12 at 11:27

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

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.

link

answered Sep 03 '12 at 06:32

Dmitry's gravatar image

Dmitry
1111

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

link

answered Sep 04 '12 at 13:07

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

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

link

answered Sep 05 '12 at 09:24

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

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:

  • POST xml content (create object on server) - .PostXML() return Response object and resonse code and headers available as Response property and method.
  • PUT exactly same xml content (update object on server) - .PutText(...) return string and I need manualy parse http headers from Http object.

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.

link

answered Sep 05 '12 at 09:46

Dmitry's gravatar image

Dmitry
1111

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.)

link

answered Sep 05 '12 at 13:57

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

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.

link

answered Sep 06 '12 at 03:28

Dmitry's gravatar image

Dmitry
1111

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).

link

answered Sep 06 '12 at 03:34

Dmitry's gravatar image

Dmitry
1111

I checked and found both bug are fixed.

link

answered Sep 06 '12 at 04:34

Dmitry's gravatar image

Dmitry
1111

Your answer
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:

×35
×1
×1

Asked: Aug 31 '12 at 06:55

Seen: 1,506 times

Last updated: Sep 06 '12 at 04:34

powered by OSQA