Mem*_*his 7 c# url asp.net-mvc external call
第一篇文章在哪里.所以最好把它变成一个好的.
我有一个ASP.NET MVC 2 Web应用程序,我有一个actionResult我需要为我打电话.
问题是我需要这个AR来处理一些数据操作,之后我需要它来调用外部URL,这实际上是一个处理向我们公司手机电话发送消息的公司模块.
它只需要调用如下所示的URL:
string url = "http://x.x.x.x/cgi-bin/npcgi?no=" + phoneNumber + "&msg=" + message;
Run Code Online (Sandbox Code Playgroud)
我不需要任何回复信息或任何东西.只想调用外部URL,这当然超出了我自己的Web应用程序的范围.(我不想重定向).必须在GUI后面调用该URL,而无需用户意识到.并且他们正在查看的页面不得受到影响.
我尝试过:
Server.Execute(url);
Run Code Online (Sandbox Code Playgroud)
但是没有用.我听说有些人通过在页面上隐藏iFrame来解决这个问题.将src设置为url可能需要然后以某种方式执行该操作以实例化调用.它对我来说似乎并不优雅,但如果这是唯一的解决方案,那么有没有人有一个如何完成的例子.或者,如果你有一个更圆滑的建议,我都是耳朵.
我终于得到了这段代码:
string messageToCallInPatient = "The doctor is ready to see you in 5 minutes. Please wait outside room " + roomName;
string url = "http://x.x.x.x/cgi-bin/npcgi?no=" + phoneNumber + "&msg=" +
messageToCallInPatient;
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(string.Format(url));
webReq.Method = "GET";
HttpWebResponse webResponse = (HttpWebResponse)webReq.GetResponse();
//I don't use the response for anything right now. But I might log the response answer later on.
Stream answer = webResponse.GetResponseStream();
StreamReader _recivedAnswer = new StreamReader(answer);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
20293 次 |
最近记录: |