login about faq

Hello,

I have not 100% tested this, but this is the behaviour I'm seeing, making me think it is a possible bug.

Request: http://www.somesite.com/something.html
------------------------------------------------
Response:
Date: Sat, 13 May 2017 10:02:08 GMT
Set-Cookie: lang=english; domain=.somesite.com; path=/
Set-Cookie: code=12345abcde; domain=.somesite.com; path=/; expires=Sun,
14-May-2017 10:02:08 GMT
Location: //www.somesite.com/foebar.php
Connection: close
Transfer-Encoding: chunked
Content-Type: application/cgi
------------------------------------------------
rest.ResponseStatusCode = 302
rest.RedirectUrl() ==> http://www.somesite.com/foebar.php
Request: http://www.somesite.com/foebar.php
NOTE: Cookie NOT set
------------------------------------------------
Response:
exactly the same as above (except different times)
------------------------------------------------
rest.ResponseStatusCode = -1
rest.RedirectUrl() ==> http://www.somesite.com/foebar.php

I expect an error text, due to ResponseStatusCode = -1. However:

ChilkatLog:
  RedirectUrl:
    DllDate: May 12 2017
    ChilkatVersion: 9.5.0.67
    UnlockPrefix: *REMOVED*
    Architecture: Little Endian; 64-bit
    Language: .NET 4.6 / x64
    VerboseLogging: 1
    url: http://www.somesite.com/foebar.php
    Success.
  --RedirectUrl
--ChilkatLog

So. My assumption is that the responseStatusCode is set to -1 due to the fact that the new location URL is the same as the previous. Ifso, that is a bug. The page was correctly loaded and thus statuscode 302 should be given (in this situation). Hooever, perhaps with a remark in the verbose logging that the new URL is the same as the previous one (This is the end-user's problem)

In the above example, the server wants you to set a cookie, if not it keeps requesting you to do so untill you ave set it.

Which brings me to the request if it is possible to add cookie support (that is available in the HTTP module) to the REST module? Clearly I did not build my cookie integration very well, causing the problem to surface... I found that this has been requested before: http://www.chilkatforum.com/questions/11395/cookie-support-in-rest-module


EDIT After fixing my cookiehandler, the problem remained. Upon further investigation I now get the error

responseHeader: [2ef9
Set-Cookie: ....and allot more header...
]
    Unrecognized 1st response line.
    firstLine: 2ef9
    Failed.
  --ReadResponseHeader
--ChilkatLog

So, I guess the question changes to:

When calling rest.ReadResponseHeader(); gives an error, why is the field rest.ResponseHeader not being updated?

asked May 13 at 06:30

timu's gravatar image

timu
72

edited May 13 at 08:49


The Chilkat REST API provides the flexibility to break up a single HTTP request/response into separate method calls. For example, you can send a POST and get the entire response header + body in a single call like this:

string responseBody = rest.FullRequestFormUrlEncoded(httpVerb,uriPath);
or you could break it up into separate calls:
bool success = rest.SendReqFormUrlEncoded(httpVerb,uriPath);
// check for success/failure...
int statusCode = rest.GetResponseHeader();
string responseBody = rest.ReadRespBodyString();

If you choose to do the latter, then you must read the response body after reading the header (because it's coming whether you want it or not). I think what you're doing is reading the response header, and then seeing that it's a 302 redirect, you forget to read the response body. You can see from the response header that a body in the "chunked encoding" is coming:

Date: Sat, 13 May 2017 10:02:08 GMT
Set-Cookie: lang=english; domain=.somesite.com; path=/
Set-Cookie: code=12345abcde; domain=.somesite.com; path=/; expires=Sun,
14-May-2017 10:02:08 GMT
Location: //www.somesite.com/foebar.php
Connection: close
Transfer-Encoding: chunked
Content-Type: application/cgi
If you neglect to read the response body, and then send another HTTP request (on the same connection), then when you read the response header, the data you'll get is the chunked response body from the previous request.

link

answered May 16 at 15:51

chilkat's gravatar image

chilkat ♦♦
12.8k317366476

That makes 100% sense. And in fact, is most likel the cause of the problem. I now also understand why for some sites I had to setup a new connection, even though the site did allow keep-alive. Small note for ppl who get confused: GetResponseHeader --> ReadResponseHeader (at least in C#)

(May 17 at 12:51) timu
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:

×15
×3

Asked: May 13 at 06:30

Seen: 305 times

Last updated: May 17 at 12:51

powered by OSQA