Acerca de %Net.HttpRequest
Tengo el siguiente código, con el que pretendo enviar el fichero pepe.XML que está en mi directorio C:\TEMP:
S httprequest.Username="dfgsdgsd"
S httprequest.Password="sdfbnnb"
S httprequest.Port=2222
S httprequest.Server="https://app.net"
D httprequest.SetParam("API-Key","jh2871371naou1b82397")
D httprequest.SetParam("content-type", "application/xml")
D httprequest.Post("C:\TEMP\pepe.XML",2)
S response=httprequest.HttpResponse
w !,response
(Los datos no son reales. Supongo que Username, Password y Port no es necesario)
No hace nada, y no se ni si se conecta.
¿Qué hago mal
Comments
Hola @Jaume Marcet!
Echa un vistazo a este código de ejemplo que me ha sugerido nuestro amigo el chatbot de IA:
Class objectscript.postXML
{
ClassMethod test() {
Set HTTPRequest = ##class(%Net.HttpRequest).%New()
Set HTTPRequest.ContentType = "text/xml"
Set HTTPRequest.NoDefaultContentCharset = 1
Set HTTPRequest.Server = "wph.foactive.com" // Specify server address here
Set HTTPRequest.Location = "/ITOMCZ" // Specify location or endpoint here
// Modify headers if necessary
Do HTTPRequest.RemoveHeader("User-Agent")
Do HTTPRequest.RemoveHeader("Accept-Encoding")
Do HTTPRequest.RemoveHeader("Connection")
Do HTTPRequest.SetHeader("Expect", "100-continue")
// Open XML file and copy its content into the request body
Set RequestXML = ##class(%Library.File).%New("c:\\path\\to\\your\\file.xml") // Specify file path here
Do RequestXML.Open("RS")
Do HTTPRequest.EntityBody.CopyFrom(RequestXML)
Do RequestXML.%Close()
// Send the request
Set sc = HTTPRequest.Post(HTTPRequest.Location)
// Check the response
If $$$ISOK(sc) {
Write HTTPRequest.HttpResponse.StatusCode, !
Write HTTPRequest.HttpResponse.Data.Read(), !
} Else {
// Handle errors
Write "Error in request: ", $System.OBJ.DisplayError(sc), !
}
}
}@Jaume Marcet ¿Has podido probar el código?
Me da:
301
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
Buenas, eso tiene pinta de que hay una redirección a la URL a la que estás invocando.