Please enable JavaScript to view this site.

A-Shell Reference

Navigation: Subroutines > HTTP

Customizing GET Headers

Scroll Prev Top Next More

As with other request methods, the XHTTPF_REQGETX flag will generate a standard set of headers to accompany the GET request. For example, the URL

https://www.googleapis.com/drive/v3/files?key=AIzaS9UiXD_1LX,Dn04MzjWR8yQ-Z HTTP/1.1

 

might auto expand into the following:

GET /drive/v3/files?key=AIzaS9UiXD_1LX,Dn04MzjWR8yQ-Z HTTP/1.1

Host: www.googleapis.com

Content-Type: application/x-www-form-urlencoded

 

But in some cases you need to either change one of the automatic headers or add your own. For example, Google API requests typically require an Authorization header containing your access token, and may require an Accept header to indicate the acceptable response format, e.g.

GET /drive/v3/files?key=AIzaS9UiXD_1LX,Dn04MzjWR8yQ-Z HTTP/1.1

Host: www.googleapis.com

Accept: application/json

Content-Type: application/x-www-form-urlencoded

Authorization: Bearer xcl89SDFweln1890sdfa90s12435...

 

To achieve the desired headers, you can use the same technique described in Customizing POST headers. However, since most GET requests don't require a request body, it is probably more convenient to drop the XHTTPF_FILEREQ and just supply the headers as a string, e.g.

url$ = "https://www.googleapis.com/drive/v3/files?key=" + apikey$ + " HTTP/1.1"

flags = XHTTPF_REQGETX + XHTTPF_HDRBODY + XHTTPF_FILERESP + XHTTPF_SSL 

request$ = "Authorization: Bearer " + access'token$ &

    + chr(13) + chr(10) + "Accept: application/json" 

xcall HTTP, XHTTPOP_REQ, status, flags, url$, request$, response$

 

Note that you still need the XHTTPF_HDRBODY flag, but no XHTTPF_REQFILE. Just concatenate your desired headers with chr(13)+chr(10) between them.