Archived Forum Post

Index of archived forum posts

Question:

Formatting a get request

Dec 16 '13 at 10:50

I am being asked to send this sample request using HTTPS abd and receive a response

https://www.sample.com/Authenticate?username=tuser@test.com&password=123456

I'm doing this to try to accomplish this (following your example codes as best I could)

 HttpsClient.Accept := 'application/json' ;    
 endpointDomain := 'www.sample.com';
 endpointPort := 443 ;
 endpointSsl := 1;

 request := TChilkatHttpRequest.Create(Self);
 request.Path := '/Authenticate?username=tuser%40test.com&password=123456' ;
 request.HttpVerb := 'GET';

 Memo.Lines.Add('SENDING REQUEST') ;
 response :=         HttpsClient.SynchronousRequest(endpointDomain,endpointPort,endpointSsl,request.DefaultInterface);

It doesn't seem to be working so I'm wondering if my request.path is actually how to handle this request.

Thanks for your info! jeff


Answer

A GET request is an HTTP request where the params are provided in the query part of the URL -- which is the part that follows the "?" and is composed of name=value pairs, concatenated with "&".

The path part of the URL is that part prior to the "?", excluding the domain and port.

The request.Path property should be set to the path part of the URL. In this case, it would be "/Authenticate".

The params should be added by calling request.AddParam(name,value), once per param.

If the request.HttpVerb is set to "GET", then the request will be formatted as a GET request where the params are part of the URL (in the query part of the URL). If the request.HttpVerb is "POST", then the params are in the body of the HTTP request (i.e. the MIME body) and the encoding, by default is application/x-www-form-urlencoded. What this means is that the params are passed in the MIME body of the request in the exact same format as they would occur in the URL. The only difference is where they are located in the request. The GET is limited in how much data can be provided in the params because of URL length limitations.