setContentType

setContentType(value: String,
               index: Integer io);

The setContentType method of the JadeHTTPConnection class sets "Content-Type" HTTP headers.

The value parameter specifies the string value for the Content-Type key; for example, "text/xml; charset=utf-8".

If you specify a value for the index parameter and the Content-Type key exists at the specified position in the list of headers, the corresponding entry is removed from the list if the value is null. If the value is non-null, the corresponding value is replaced. If there is no Accept key in the specified position, the key-value pair is added at this position.

The following example sends a request to an OAuth server.

docExample1();
vars
    http : JadeHTTPConnection;
    indx : Integer;
begin
    create http transient;
    http.setContentType("application/x-www-form-urlencoded", indx);
    http.url := 'https://api-name/service/security/oauth2/token-value';
    http.sendRequest(http.Verb_POST, null, null);
    write http.readBody(0).ansiToString;
    http.inspectModal;
epilog
    delete http;
end;

The following example returns the credentials in the body of the content.

docExample2();
vars
    http : JadeHTTPConnection;
    indx : Integer;
begin
    create http transient;
    http.setContentType("application/x-www-form-urlencoded", indx);
    http.url := 'https://api-name/service/security/oauth2/token';
    http.sendRequest(http.Verb_POST, null, "token-value");
    write http.readBody(0).ansiToString;
    http.inspectModal;
epilog
    delete http;
end;