PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → Adding headers to an httpRequest variable in WD 20
Adding headers to an httpRequest variable in WD 20
Iniciado por guest, 11,nov. 2015 00:35 - 2 respuestas
Publicado el 11,noviembre 2015 - 00:35
I am having difficulties when passing header information in an httpRequest variable. If you look at the attached code the HTTPRequest function works fine but then when using the httpRequest variable with exactly the same header the website responds with an error. I need to use httpRequest variable because I need to use PUT elsewhere with the API which is not supported by the HTTPRequst function.
Am I passing the header information correctly to the httpRequest variable - if not how should it be passed?
sHeader is string
sUrltouse is string
HTTP_Res is string
HTTPError is string


sUrltouse = "a website"
sHeader = "Accept: application/json"+CR
testapi is httpRequest
testapi..Method = httpGet
testapi..URL = sUrltouse

testapi..IgnoreError = httpIgnoreInvalidCertificate

testapi..Header["A"] = sHeader
HTTP.IgnoreError = httpIgnoreInvalidCertificate


HTTPRequest(sUrltouse,"",sHeader,"","","","")


HTTP_Res = HTTPGetResult()
IF Length(HTTP_Res) = 0 THEN
// Error of the Web server, the error details are found in the header of the page
HTTPError = HTTPGetResult(httpHeader)
Error(HTTPError)
END
HTTPError = HTTPGetResult(httpHeader)
Info(HTTPError)


Info(HTTP_Res)


apiresponse is httpResponse = HTTPSend(testapi)
IF ErrorOccurred THEN
Error(ErrorInfo(errFullDetails))
ELSE
Info(apiresponse..RoughHeader)
Info(apiresponse..Content)


END
Publicado el 11,noviembre 2015 - 18:46
What is the error being returned?

Have you tried hitting the site with Chrome and then checking the console to see what "Content-Type" is being passed in the headers tab?

Thanks
Georgio
Publicado el 12,noviembre 2015 - 10:04
Hi,

I use the header in this way

MyRequest..Header["Mode"] = sCustomHeader+[CRLF]
and this works.

Also make sure the ContentType is set correctly as Georgio described. You can use fiddler or SOAPUI to test to see what info needs to be passed or is passed correctly to the server.

Danny