Tengo un proyecto para el trabajo utilizando SOAP. Como nunca habíamos usado ese protocolo, comenzamos a estudiar cosas al respecto y por fin, dimos con la solución a nuestros problemas y eso es MSXML y el XMLHTTPRequest.
He estado haciendo pruebas, y tengo una página en ASP que actualiza el archivo doGoogleSearch.xml y pone el termino a buscar en el lugar apropiado, despues, en el cliente, uso el XMLHTTPRequest y mando el archivo xml a Google, recibo el archivo con los links y lo pongo en un TextArea, solo para ver que en realidad funciona la comunicación. Hasta allí todo bien.
Mi problema comienza cuando intento la segunda consulta, se supone que el archivo doGoogleSearch.xml se actualiza dinámicamente antes de hacer el GET y Post del XMLHTTPRequest. Y de hecho, si se actualiza, porque al revisar el archivo xml está tal y como lo necesito, con el nuevo término de búsqueda. Pero de algún modo, el POST está mandando el archivo XML anterior, uno que ya ni siquiera existe porque fue sobreescrito.
Pienso que el archivo queda en algún tipo de cache, entonces creo que necesito forzar el GET para que obtenga el archivo que recién acabo de modificar.
Alguien sabe si se puede hacer eso y cómo?
Este es mi código.
Código:
function sendXML() {
var req = new ActiveXObject("Microsoft.XMLHTTP");
var req2 = new ActiveXObject("Microsoft.XMLHTTP");
req.open("POST", "http://api.google.com/search/beta2",true);
req.setRequestHeader("Man", "POST http://api.google.com/search/beta2 HTTP/1.1");
req.setRequestHeader("MessageType", "CALL");
req.setRequestHeader("Content-Type", "text/xml");
if (req2) {
req2.onreadystatechange = function() {
if (req2.readyState == 4 && req2.status == 200) {
req.send(req2.responseText);
}
};
}
req2.open('GET', 'http://tomsrtds1/ppts/toms/xmlTest/doGoogleSearch.xml',true);
req2.send(null);
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4 && req.status == 200) {
document.all.xmlResult.value=req.responseText;
}
};
}
Esto si funciona, pero mandando el primer XML que generé.
Y el archivo ASP completo es
Código:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% Response.CacheControl = "no-cache" %>
<%
XMLLoaded = false
if Request.Form("txtSearch") <> "" then
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.Async=false
if objXML.Load(Server.MapPath("doGoogleSearch.xml")) then
' Process the XML File
objXML.getElementsByTagName("q").item(0).text = Request.Form("txtSearch")
Response.Write(objXML.getElementsByTagName("q").item(0).text )
objXML.save(Server.MapPath("doGoogleSearch.xml"))
XMLLoaded = true
else
Dim strErrText
strErrText = ""
Dim xPE
' Obtenga el objeto ParseError
Set xPE = objXML.parseError
With xPE
strErrText = "Your XML Document failed to load" & _
" due the following error." & vbCrLf & _
"Error #: " & .errorCode & ": " & xPE.reason & _
"Line #: " & .Line & vbCrLf & _
"Line Position: " & .linepos & vbCrLf & _
"Position In File: " & .filepos & vbCrLf & _
"Source Text: " & .srcText & vbCrLf & _
"Document URL: " & .url
End With
End If
end if
%>
<html>
<head>
<title>Alex's Implementation of Google</title>
<%
if XMLLoaded then
%>
<script type="text/javascript" language="JavaScript">
<!--
function sendXML() {
var req = new ActiveXObject("Microsoft.XMLHTTP");
var req2 = new ActiveXObject("Microsoft.XMLHTTP");
req.open("POST", "http://api.google.com/search/beta2",true);
req.setRequestHeader("Man", "POST http://api.google.com/search/beta2 HTTP/1.1");
req.setRequestHeader("MessageType", "CALL");
req.setRequestHeader("Content-Type", "text/xml");
if (req2) {
req2.onreadystatechange = function() {
if (req2.readyState == 4 && req2.status == 200) {
req.send(req2.responseText);
}
};
}
req2.open('GET', 'http://tomsrtds1/ppts/toms/xmlTest/doGoogleSearch.xml',true);
req2.send(null);
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4 && req.status == 200) {
document.all.xmlResult.value=req.responseText;
}
};
}
}
function MM_callJS(jsStr) { //v2.0
return eval(jsStr)
}
//-->
</script>
<%
end if
%>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body <%
if XMLLoaded then
%>onLoad="MM_callJS('sendXML();')"
<%
end if
%>>
<h1 align="center"><em>Enter your Search Words </em></h1>
<form name="form1" method="post" action="">
<div align="center">
<p>
<input name="txtSearch" type="text" id="txtSearch">
</p>
<p>
<input name="button" type="submit" id="button" value="Search">
</p>
<p>
<textarea name="xmlResult" cols="100" rows="100" id="xmlResult"></textarea>
</p>
</div>
</form>
<%
If strErrText <> "" then
Response.Write(strErrText)
end if
%>
<p align="center"><em></em></p>
</body>
</html>