EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Trying to use HttpsClient

Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages
#27273
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 :

https://www.sample.com/Authenticate?username=name%40mailinator.com&password=123456

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 ;

try
try
HttpsClient.Get( AuthenticateString );
finally
HttpsClient.Close(true);
end;
except
on E : Exception do
begin
Memo.Lines.Add('Exception: ' + E.Message);
end;
end;

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
DATA 1
On Progress Total=1 Current : 1
Document End
Close
Close


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.
Jeff
#27274
Posted: 11/21/2013 02:04:24
by Vsevolod Ievgiienko (EldoS Corp.)

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.
#27275
Posted: 11/21/2013 02:08:19
by Eugene Mayevski (EldoS Corp.)

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
#27276
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?
#27277
Posted: 11/21/2013 02:41:50
by Eugene Mayevski (EldoS Corp.)

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
#27278
Posted: 11/21/2013 02:42:39
by Vsevolod Ievgiienko (EldoS Corp.)

Quote
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.
#27281
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!
#27283
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!
Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.

Reply

Statistics

Topic viewed 1516 times

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




|

Back to top

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

Got it!