El resultado que tomo es como este:
Código XML:
Ver original
<?xml version="1.0" encoding="utf-8"?> <response> <status_code>200</status_code> <status_txt>OK</status_txt> <data> <url>http://kapis.us/l4nRWO</url> <hash>l4nRWO</hash> <global_hash>iWmKxG</global_hash> <long_url>http://www.kapistore.com/producto.asp?id=3</long_url> <new_hash>0</new_hash> </data> </response>
Hasta aqui bien, tomo el valor de URL con esta clase:
Código ASP:
Ver original
class KapiLink private m_StrProvider,m_StrApiUrl,m_StrUserName,m_StrApiKey public property let aspSetProvider(strProvider) m_StrProvider = Lcase(strProvider) select case m_StrProvider case "bitly" m_StrApiUrl = "http://api.bitly.com/v3/shorten?login=[:LOGIN:]&apiKey=[:API:]&longUrl=[:URL:]&format=xml" case "isgd" m_StrApiUrl = "http://is.gd/api.php?longurl=[:URL:]" case else m_StrApiUrl = "http://tinyurl.com/api-create.php?url=[:URL:]" end select end property public property let aspSetUser(strUser) m_StrUserName = strUser end property public property let aspSetApi(strApi) m_StrApiKey = strApi end property sub class_initialize() me.aspSetProvider = "tinyurl" m_StrUserName = m_StrApiKey = "" end sub sub class_terminate() end sub private function aspGrabUrl(strUrl) select case m_StrProvider case "bitly" Dim oXmlDom,strGrabUrl,strRespuesta set oXmlDom = Server.CreateObject("Microsoft.XMLDOM") oXmlDom.async = false oXmlDom.setProperty "SelectionLanguage", "XPath" oXmlDom.loadxml(strUrl) strGrabUrl = oXmlDom.selectSingleNode("/response/data/url").Text Set oXmlDom = Nothing aspGrabUrl = strGrabUrl case else aspGrabUrl = strUrl end select end function public function aspShortUrlExec(strUrl) if Len(m_StrApiUrl) > 0 then Dim oXml,strRealUrl,strShortUrl strRealUrl = Replace(m_StrApiUrl, "[:URL:]", strUrl, 1, -1, 1) strRealUrl = Replace(strRealUrl, "[:LOGIN:]", m_StrUserName, 1, -1, 1) strRealUrl = Replace(strRealUrl, "[:API:]", m_StrApiKey, 1, -1, 1) set oXml = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0") oXml.Open "GET", strRealUrl, false oXml.Send null strShortUrl = oXml.responseText Set oXml = nothing aspShortUrlExec = aspGrabUrl(strShortUrl) else aspShortUrlExec = false end if end function end class
Que como les digo, funciona bien, a esta clase la llamo con esta funcion:
Código ASP:
Ver original
function asp_short_url(strUrl) Set obj = new KapiLink obj.aspSetProvider = "bitly" obj.aspSetUser = "sjam7" obj.aspSetApi = "R_dcdfcf22fc16bfb1fbexxxxxxxxxxxxxx" bitlyUrl = obj.aspShortUrlExec(Server.URLEncode(strUrl)) Response.Write(bitlyUrl) Set obj = nothing End Function
y el response.write aparece en un campo de formulario con esto:
<input type="text" name="link_corto" value="<%=asp_short_url(link)%>" size="50">
Como podria agregarle a la clase para que pueda, en la funcion verificar si el status es OK
e imprimir en pantalla el resultado o en caso contrario mostrar el error???
Como puedo agregarle un resultado?
Supongo que es agregando algo como:
strGrabUrl = oXmlDom.selectSingleNode("/response/status_txt").Text
Pero no se como obtenerla o sacarla en la funcion, gracias y espero su valiosa ayuda como siempre