﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server 2008 - General  / Call a URL and pass a parameter in the URL (http post) / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 25 May 2013 16:15:44 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Call a URL and pass a parameter in the URL (http post)</title><link>http://www.sqlservercentral.com/Forums/Topic1382247-391-1.aspx</link><description>Received an pm asking for more details on the programming portion of this, as CLR can be a bit scary the first time around.hopefully, this can get someone started, but there's a lot of tutorials out there; I'm better with specific questions rather than overall processes.1. I believe you'll need to set your database to TRUSTWORTHY.so assuming you create a brand new database named "Test" so you can be sure this works, you need to run this command:[code]ALTER DATABASE Test SET TRUSTWORTHY ON[/code]2. it's a lot easier to modify something that already exists, than it is to start fresh.So I slapped together a Visual Studio Database project real quick.grab this zip file containing a Visual Studio 2010 and open it in in visual studio.[b][url=http://www.stormrage.com/SQLStuff/CLRWeb.zip]CLRWeb.zip [/url][/b]3. go to the project properties and change the database connection shown below:[img]http://www.stormrage.com/SQLStuff/clr_change_database.png[/img]4. Use the Build&amp;gt;&amp;gt;Build CLRWeb command as shown in the screenshot above.5. Use the Build&amp;gt;&amp;gt;Deploy CLRWeb  command as shown in the screenshot above.If the build fails, Control+alt+O takes you to the output &amp;#119;indow....review the error. 6. Once deployed, use the same test method I pasted before to test it in TSQL[code]Use Test;GOdeclare @url varchar(1000)declare @int intSET @int = 59SET @url='http://ccv.viatelecom.com/wcbr/wsRealTimeMode.php?adm=10764&amp;sid=3112&amp;nocall=' + CONVERT(varchar,@int)declare @results varchar(max)SELECT @results = dbo.CLR_WebQuery(@url)print @results[/code]If it works, you can now start customizing it by changing the project name or whatever else you need to do, but it would be good to go as is.you might want to consider using a certificate instead of setting Trustworthy, but that should get you started.if you were going to use it as is, you would  repeat the same steps above so you point at the final target database.</description><pubDate>Thu, 08 Nov 2012 12:08:20 GMT</pubDate><dc:creator>Lowell</dc:creator></item><item><title>RE: Call a URL and pass a parameter in the URL (http post)</title><link>http://www.sqlservercentral.com/Forums/Topic1382247-391-1.aspx</link><description>oh yeah!!![img]http://www.stormrage.com/SQLStuff/TSQL_Hammer.png[/img]</description><pubDate>Thu, 08 Nov 2012 09:23:27 GMT</pubDate><dc:creator>Lowell</dc:creator></item><item><title>RE: Call a URL and pass a parameter in the URL (http post)</title><link>http://www.sqlservercentral.com/Forums/Topic1382247-391-1.aspx</link><description>LOL Lowell you really pulled out all the stops with your T-SQL hammer on this one!!! Talk about brute force. I don't remember the link to the hammer on your site but this conjured up memories of that one. :-D</description><pubDate>Thu, 08 Nov 2012 08:18:07 GMT</pubDate><dc:creator>Sean Lange</dc:creator></item><item><title>RE: Call a URL and pass a parameter in the URL (http post)</title><link>http://www.sqlservercentral.com/Forums/Topic1382247-391-1.aspx</link><description>I'd do exactly what Sean is recommending...I'd have a service slam the web site and store the results in a table, all outside of TSQL.Now, having said that, just to be stubborn, i got out my "gotta do it in TSQL" hat, and created a CLR to return a web page, or in this case a web request.It works via TSQL, and takes about 6 seconds or so to get the results...so it's not all that quick, but we are talking about the web, here.the call:[code]declare @url varchar(1000)declare @int intSET @int = 42SET @url='http://ccv.viatelecom.com/wcbr/wsRealTimeMode.php?adm=10764&amp;sid=3112&amp;nocall=' + CONVERT(varchar,@int)declare @results varchar(max)SELECT @results = dbo.CLR_WebQuery(@url)print @results/*OK#0 appels effectifs / #42 / #0*/[/code]and the CLR definition:[code] 'requires    'Imports System.Net    &amp;lt;Microsoft.SqlServer.Server.SqlFunction()&amp;gt;    Public Shared Function CLR_WebQuery(ByVal URL As String) As SqlChars ' varchar(8000) = SqlString, SqlChars=varchar(max)        Dim request As WebRequest = HttpWebRequest.Create(URL)        Using response As WebResponse = request.GetResponse()            Using dataStream As Stream = response.GetResponseStream()                Using reader As New StreamReader(dataStream)                    Dim responseFromServer As String = reader.ReadToEnd()                    Return New SqlChars(New SqlString(responseFromServer))                End Using            End Using        End Using        request = Nothing    End Function[/code]</description><pubDate>Thu, 08 Nov 2012 08:08:26 GMT</pubDate><dc:creator>Lowell</dc:creator></item><item><title>RE: Call a URL and pass a parameter in the URL (http post)</title><link>http://www.sqlservercentral.com/Forums/Topic1382247-391-1.aspx</link><description>I would not do this in sql. This sounds like you need a simple program to do this. If I had this assignment I would generate a .net windows service for this.</description><pubDate>Thu, 08 Nov 2012 07:42:34 GMT</pubDate><dc:creator>Sean Lange</dc:creator></item><item><title>RE: Call a URL and pass a parameter in the URL (http post)</title><link>http://www.sqlservercentral.com/Forums/Topic1382247-391-1.aspx</link><description>I may be overcomplicating things, and there may be a much more simple way to do this, but for the first part, you're looking at creating an agent job that fires up a select, using the table output as a variable;i.e. @URL is your URL path@nocall = your selected record resultset @nocall = select &amp;lt;field&amp;gt; from &amp;lt;table&amp;gt; where &amp;lt;whichever criteria you're using to choose the number&amp;gt;set @URL = 'http://ccv.viatelecom.com/wcbr/wsRealTimeMode.php?adm=10764&amp;sid=3112&amp;nocall='@nocallYou can then use a cmdexec command to fire up Internet Explorer with the URL:(Create a text document with the following entry:@start "" /b "C:\Program Files\Internet Explorer\iexplore.exe" %*Rename the file AutoURL.bat)You could then call this from the command line;*exec AutoURL www.google.com for exampleYou would have to pass the variable output to the command (i.e. AutoURL @URL)Personally, I would consider using a VB Script for the whole job, rather than anything SQL offers on its own.The second part may be more difficult, as it will depend on the structure of the website and what you're actually able to read from it.</description><pubDate>Thu, 08 Nov 2012 04:20:11 GMT</pubDate><dc:creator>McSQL</dc:creator></item><item><title>Call a URL and pass a parameter in the URL (http post)</title><link>http://www.sqlservercentral.com/Forums/Topic1382247-391-1.aspx</link><description>Hello ,Can somebody please assist me, i need to call this URL http://ccv.viatelecom.com/wcbr/wsRealTimeMode.php?adm=10764&amp;sid=3112&amp;nocall=XXXX where XXXX is a number which we obtain from a table by a simple select Query.create schedule Job which execute every 1 minute and also to save the reponse we obtain from the URL to a database. Any idea ?Thanks</description><pubDate>Wed, 07 Nov 2012 20:55:58 GMT</pubDate><dc:creator>mooneer3112</dc:creator></item></channel></rss>