asp.net - 将 QueryString 转发到另一台服务器

标签 asp.net vb.net http query-string

我有一个 web 应用程序,它接受来自外部服务器的 messageid 和状态作为 QueryString。我正在将 webapp 迁移到新服务器,但我需要新服务器将 QueryString 转发到旧服务器,以防旧服务器仍在等待更新,直到我可以让我的客户迁移过来。

外部网站使用 ?MSGID=12345678&RESPONSE=0 调用我的 webapp

例如:

http://dlrnotify.newserver.com/GetResponse.aspx?MSGID=12345678&RESPONSE=0

我需要 GetResponse.aspx 背后的代码在本地处理消息,然后将请求转发到旧服务器。例如,调用:

http://dlrnotify.oldserver.com/GetResponse.aspx?MSGID=12345678&RESPONSE=0

我真的不想将用户重定向到旧的网络服务器,只是为了从我的应用程序传递查询字符串。

我可以通过调用 Response.QueryString.ToString() 获取 QueryString 我只需要知道如何将它发布到旧服务器而不打乱任何东西。

抱歉,如果这是一个愚蠢的问题,我不经常使用网络应用程序,而且显然使用了错误的搜索词。

最佳答案

您可以为此使用 HttpWebRequest 和 HttpWebResponse。下面是一个使用这些的例子

  Uri uri = new Uri("http://www.microsoft.com/default.aspx");
  if(uri.Scheme = Uri.UriSchemeHttp) 
  {
        HttpWebRequest request = HttpWebRequest.Create(uri);
        request.Method = WebRequestMethods.Http.Get;
        HttpWebResponse response = request.GetResponse();
        StreamReader reader = new StreamReader(response.GetResponseStream());
        string  tmp = reader.ReadToEnd();
        response.Close();
        Response.Write(tmp);
 }

关于如何使用 HttpWebRequest 将数据发布到远程网页的示例代码

   Uri uri = new Uri("http://www.amazon.com/exec/obidos/search-handle-form/102-5194535-6807312");
   string data = "field-keywords=ASP.NET 2.0";
   if (uri.Scheme == Uri.UriSchemeHttp)
   {
       HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
       request.Method = WebRequestMethods.Http.Post;
       request.ContentLength = data.Length;
       request.ContentType = "application/x-www-form-urlencoded";
       StreamWriter writer = new StreamWriter(request.GetRequestStream());
       writer.Write(data);
       writer.Close();
       HttpWebResponse response = (HttpWebResponse)request.GetResponse();
       StreamReader reader = new StreamReader(response.GetResponseStream());
       string tmp = reader.ReadToEnd();
       response.Close();
       Response.Write(tmp);
   }

关于asp.net - 将 QueryString 转发到另一台服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14138516/

相关文章:

java - 服务器发送的事件 Android

asp.net - 亚音速和ADO.NET Entity Framework哪个更快

asp.net - SqlCommand占位符参数: "Incorrect syntax near ' ?'" and "Must declare the scalar variable @param"?

html - 如何获得 CSS 类选择器来覆盖 input[readonly] 选择器?

c# - 上传大于 4096 KB 的文件失败!

vb.net - VB无法访问不同项目的类,相同的解决方案

vb.net - 从 VB.NET 与 node.js 通信

vb.net - Task.Factory.StartNew的正确语法是什么?

python - 检查 Python 请求库是否正在下载文件

java - 您如何在数据 block 到达时使用 java.net.http 读取和打印分块的 HTTP 响应?