Yes, as a matter of fact I do. Here is the CLR source (see below).
See another article I wrote "Deploying CLR Assemblies with T-SQL[/url]" for one way to deploy CLR assemblies like this one.
//------start of CLR Source------
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Net;
using System.IO;
public partial class OpsStreamProcedures
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void HTTPGet(
SqlString URL,
SqlString HTTPMethod,
SqlString ContentType,
SqlString DataToSend,
SqlString User,
SqlString Password,
out SqlInt32 HTTPStatus,
out SqlString HTTPStatusText,
out SqlBinary ResponseBinary,
out SqlString ErrorMsg
)
{
string thisURL = Convert.ToString(URL);
string thisHTTPMethod = Convert.ToString(HTTPMethod);
string thisContentType = Convert.ToString(ContentType);
string thisDataToSend = Convert.ToString(DataToSend);
string thisUser = Convert.ToString(User);
string thisPassword = Convert.ToString(Password);
string thisErrorMsg = new string();
byte[] binData = new byte[1];
byte[] buffer = new byte[4096];
Int32 responseStatusCode = 0;
string responseStatusDescription = null;
try
{
HttpWebRequest request = null;
HttpWebResponse response = null;
Stream responseStream = null;
request = (HttpWebRequest)WebRequest.Create(thisURL);
request.UserAgent = "SQL CLR Client";
if (thisHTTPMethod.Length == 0) {
request.Method = "GET";
}
else {
request.Method = thisHTTPMethod; //PUT/POST/GET/DELETE
}
request.ContentType = thisContentType;
if (thisDataToSend.Length > 0) {
thisErrorMsg = "thisDataToSend.Length > 0";
//convert string thisDataToSend to byte array
byte[] binSendData = System.Text.Encoding.Default.GetBytes(thisDataToSend);
//set ContentLength
request.ContentLength = binSendData.Length;
//get stream object for the request
Stream dataStream = request.GetRequestStream();
//write byte array to the stream
dataStream.Write (binSendData, 0, binSendData.Length);
//close the stream
dataStream.Close();
}
else {
request.ContentLength = 0;
}
response = (HttpWebResponse)request.GetResponse();
responseStream = response.GetResponseStream();
using(MemoryStream memoryStream = new MemoryStream())
{
int count = 0;
do
{
count = responseStream.Read(buffer, 0, buffer.Length);
memoryStream.Write(buffer, 0, count);
} while(count != 0);
binData = memoryStream.ToArray();
}
responseStatusCode = Convert.ToInt32(response.StatusCode);
responseStatusDescription = response.StatusDescription;
response.Close();
responseStream.Dispose();
}
catch (Exception ex)
{
SqlContext.Pipe.Send(ex.Message.ToString());
}
ResponseBinary = binData;
thisErrorMsg = "Hello World";
HTTPStatus = new SqlInt32(responseStatusCode);
HTTPStatusText = new SqlString(responseStatusDescription);
ErrorMsg = new SqlString(thisErrorMsg);
}
};
//------end of CLR Source------