Archived Forum Post

Index of archived forum posts

Question:

How to use chilkahttp to replace cURL

Oct 04 '16 at 18:20

Here is a cURL line used to retrieve data from a JSON Get: curl --user SomeUser:SomePassword -H "Content-Type: application/json" -X GET https://SomeServer/queue/19/jsonEditorApi.do -o "C:Program Files (x86)Microsoft Visual StudioVB98QueueMetricsqueue.txt"

-H, --header <header>

-o, --output <file> (Instead of -o, would like text be returned into a string 'ChilkatHttpResponse')

-X, --request <command> (HTTP) Specifies a custom request method to use when communicating with the HTTP server. The specified request method will be used instead of the method otherwise used (which defaults to GET).


Answer

A GET request has no request body, and therefore the Content-Type header is meaningless. (A Content-Type header only makes sense if the request has a body, such as for a POST. A GET request never has a body.) Therefore, the Content-Type header can (and should) be omitted.

That leaves just the HTTP basic authentication. Setting the Chilkat.Http.Login and Chilkat.Http.Password properties is the equivalent of "-user SomeUser:SomePassword".

To duplicate the above request, set the Login and Password properties, and then call Chilkat.Http.QuickGetStr("https://SomeServer/queue/19/jsonEditorApi.do"), which returns the response body text.