本文介绍了通过SQL发送HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用MSSQL存储过程将以下字符串发送到Web,因为我会将该字符串粘贴到Web浏览器本身。我需要具备什么以及需要在SQL2008 R2中打开什么?
http://api.thirdparty.com / http / sendmsg?user = xxxxxx& password = xxxxx& api_id = xxxxxx& to = 081234567& text =从+ sql发送+ http +
Pierre
Hi, Id like to send the following string to the web using a MSSQL stored procedure, as I would have pasted the string in the web browser itself. What do I need to have in place and what needs to be switched on in SQL2008 R2?http://api.thirdparty.com/http/sendmsg?user=xxxxxx&password=xxxxx&api_id=xxxxxx&to=081234567&text=Sending+http+from+sql
Pierre
推荐答案
-- ==================================
-- Alter Stored Procedure Template
-- ==================================
ALTER PROCEDURE GetURL
(@Username Nvarchar(50),@url NVARCHAR(MAX)= NULL OUTPUT)
AS
SELECT @url=
'http://api.thirdparty.com/http/sendmsg?user=' + username + '&password=' + password + '&api_id=' + api_id + '&to=081234567&text=Sending+http+from+sql'
FROM Userinfo WHERE username=@Username
select @url url
GO
2)将代码更新为广告d这个
2) Update your code to add this
SqlDataReader adm = null;
string outurl;
//http://www.codeproject.com/Answers/315162/how-to-create-gridview-which-has-column-and-row/?cmt=207083#cmt2_315162
SqlConnection myConnection = new SqlConnection("Data Source=MDT765;Initial Catalog=TST;User Id=sa;Password=sa@123");
myConnection.Open();
SqlCommand cmd = new SqlCommand("GetURL", myConnection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(
new SqlParameter("@username", SqlDbType.NVarChar,50));
cmd.Parameters["@username"].Value = "user1";
SqlParameter url = new SqlParameter("@url", SqlDbType.NVarChar);
// Type=null;
url.Direction = ParameterDirection.InputOutput;
url.Value = null;
url.Size = 255;
cmd.Parameters.Add(url);
adm = cmd.ExecuteReader();
if (adm.HasRows)
{
while (adm.Read())
{
outurl = adm["url"].ToString();
Response.Redirect(outurl);
}
}
//Needs proxy authentication
WebProxy proxy = new WebProxy(@"10.35.0.22:8080");
proxy.Credentials = new NetworkCredential("username", "password", "domain");
WebRequest.DefaultWebProxy = proxy;
//*** This does not work with IE - get garbage in response - will figure out //*** later
//WebProxy proxy = new WebProxy();
//proxy.Credentials = CredentialCache.DefaultCredentials;
//WebRequest.DefaultWebProxy = proxy;
SqlDataReader adm = null;
string outurl;
SqlConnection myConnection = new SqlConnection("Data Source=localhost;Initial Catalog=xxxxx;User Id=xxxxx;Password=xxxxx");
myConnection.Open();
SqlCommand cmd = new SqlCommand("GetURL", myConnection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@username", SqlDbType.NVarChar, 50));
cmd.Parameters["@username"].Value = "xxxx";
SqlParameter url = new SqlParameter("@url", SqlDbType.NVarChar);
// Type=null;
url.Direction = ParameterDirection.InputOutput;
url.Value = null;
url.Size = 255;
cmd.Parameters.Add(url);
adm = cmd.ExecuteReader();
if (adm.HasRows)
{
while (adm.Read())
{
outurl = adm["url"].ToString();
//changed for winforms app
WebRequest request = WebRequest.Create(outurl);
WebResponse response = request.GetResponse();
MessageBox.Show(response.ResponseUri.ToString());
}
}
这篇关于通过SQL发送HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!