EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Trying to use HttpsClient

Posted: 11/21/2013 01:51:44
by Jeff Newlin (Standard support level)
Joined: 12/26/2010
Posts: 19

I have been tasked to write an interface using an API. I've done this once before using the HTTPSClient - but that application used only POST commands. This new project uses the GET command as well.

Specifically I'm told that my "Request" needs to look like this :


I'm told that my "Response" will look like this :
{"code"=>"0", "description"=>"No Error.", "data"=>{"token"=>"fFqLwDwio7VwvPUek3U3"}}

I have this little bit of code using HttpsClient to send the request :

HttpsClient.SSLEnabled := TRUE ;
HttpsClient.UseHTTPProxy := False ;

HttpsClient.Get( AuthenticateString );
on E : Exception do
Memo.Lines.Add('Exception: ' + E.Message);

I was expecting this response to show up with an OnData event - but I'm only getting 1 byte back. I made this trace of the various events firing - it looks like I am getting logged on ok -

On Prepared Headers
Certificate Validate : Validate:= TRUE ( I set Validate to TRUE )
On Progress Total=163 Current : 0
On Send Data - Size = 163
On Progress Total=163 Current : 163
On Receive Headers
On Cookie : Text Length 173
On Cookie : Text Length 607
On Progress Total=1 Current : 0
Document Begin
On Progress Total=1 Current : 1
Document End

There is data delivered during the OnCookie event but it's not what I'm looking for.

Does the HttpsClient seem to be the right way of handling this task? Am I right to expect my "Response" to come over during the OnData event?

Thanks so much - I'm very new at this.
Posted: 11/21/2013 02:04:24
by Vsevolod Ievgiienko (Team)

Thank you for contacting us.

I recommend you to try our sample located in \EldoS\SecureBlackbox.VCL\Samples\Delphi\HTTPBlackbox\Client\HTTPGet. It logs all data exchange between client and server. This may highlight the reason of the problem.
Posted: 11/21/2013 02:08:19
by Eugene Mayevski (Team)

From your description it seems that the documentation for your service doesn't match actual behavior. When you call Authenticate, you get the boolean result (or maybe error code) in data, not the JSON-encoded response. The cookies should be stored for further requests and maybe they contain the authentication token.

Sincerely yours
Eugene Mayevski
Posted: 11/21/2013 02:34:30
by Jeff Newlin (Standard support level)
Joined: 12/26/2010
Posts: 19

Thank you Eugene. I think that sample code is helpful. This is what I get back :

Headers sent:
GET /Authenticate?username=sample%40mailinator.com&password=123456 HTTP/1.1
Host: www.sample.com:443
User-Agent: SecureBlackbox
Accept-Encoding: gzip, deflate
Connection: Keep-Alive

Headers received:
****> HTTP/1.1 406 Not Acceptable
Date: Thu, 21 Nov 2013 08:29:22 GMT
Content-Type: text/html; charset=utf-8
X-UA-Compatible: IE=Edge
Cache-Control: no-cache
X-Runtime: 1.077842
Content-Length: 1
Set-Cookie: --cookie data--
Set-Cookie: --cookie data--
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive

--- Document started ---

--- Document finished ---
Connection closed.

Looks like there is an error in there "HTTP/1.1 406 Not Acceptable" - maybe that's my problem? Is there a way I can change that version?
Posted: 11/21/2013 02:41:50
by Eugene Mayevski (Team)

Error message has nothing to do with the HTTP version - it's just the format the response code is sent. In OK responses you would get "HTTP/1.1 200 OK"

For me it looks like the instructions given to you need clarifications. There's no way to find out what the server doesn't like besides either having a specification of acceptable request format or the sample of the successful request sent by some other client.

Sincerely yours
Eugene Mayevski
Posted: 11/21/2013 02:42:39
by Vsevolod Ievgiienko (Team)

Looks like there is an error in there "HTTP/1.1 406 Not Acceptable" - maybe that's my problem?

Here is this code description: the requested resource is only capable of generating content not acceptable according to the Accept headers sent in the request.

I recommend you to *play* with Accept HTTP request header that can be set using TElHTTPSClient.RequestParameters.Accept property. Most likely you should set it to 'application/json' or something like that.
Posted: 11/21/2013 03:14:05
by Jeff Newlin (Standard support level)
Joined: 12/26/2010
Posts: 19

Thanks for the help - this gives me a place to start!
Posted: 11/21/2013 03:27:50
by Jeff Newlin (Standard support level)
Joined: 12/26/2010
Posts: 19

Thanks guys - setting the Accept parameter to took care of it. Your support is quite excellent!



Topic viewed 1683 times

Number of guests: 2, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS business operates as a division of /n software, inc. For more information, please read the announcement.

Got it!