我试图设置一个简单的代理服务器,将数据发布到我的代理服务器。代理服务器将把发布的数据转发给实际的服务器,并从实际的服务器获得响应。然后在发出请求的网站所读取的代理服务器上显示响应并对数据执行任何操作。 我在第一部分获取来自网站的原始发布数据时遇到了问题。看起来asmx文件总是希望将参数从参数中删除,但我的代理只想转发原始请求。它不知道这些参数。下面是一个例子请求到代理服务器: 本地主机/ mobile.asmx POST { “的userName”: “[email protected]”, “密码”: “XXXX”, “APPID”:“2302FF64-925D-4E0E -B086-73AA9FF152D8“}c#.net访问asmx服务中的原始json请求
我再一次不想获取用户名和密码。我想捕获完整的原始请求并将其转发到真实的服务器上。
我试过了很多东西。因为没有请求参数我不能使用请求。我也相信函数GETUSERTOKENLOGIN发生在原始数据流的读取之后,所以我不能再使用流来获取数据。我尝试了很多东西。
我希望这是一个超级简单的脚本,如果可能的话。以下是我最简单的例子。我知道我可以在数据中添加一个包装,但我不想那样做。
任何帮助将不胜感激。 MOBILE.ASMX
<%@ WebService Language="C#" Class="mobile" %>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Net;
using System.IO;
using System.Web.Script.Services;
using System.Text;
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class mobile : System.Web.Services.WebService
{
public mobile()
{
}
// The HelloWorld() example service returns the string Hello World.
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetUserTokenLogin()
{
// Create a new request to the mentioned URL.
WebRequest myWebRequest = WebRequest.Create("http://api.geonames.org/citiesJSON");
myWebRequest.Method = "POST";
Stream dataStream = myWebRequest.GetRequestStream();
WebResponse myWebResponse = myWebRequest.GetResponse();
// Print the HTML contents of the page to the console.
Stream streamResponse = myWebResponse.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
Char[] readBuff = new Char[256];
int count = streamRead.Read(readBuff, 0, 256);
String FullData = "";
while (count > 0)
{
String outputData = new String(readBuff, 0, count);
FullData = FullData + outputData;
count = streamRead.Read(readBuff, 0, 256);
}
// Close the Stream object.
streamResponse.Close();
streamRead.Close();
myWebResponse.Close();
return FullData;
}
}
有什么办法从asmx文件中获取原始文章?我只是建立文件。我宁愿我的客户不必经历所有的配置。是否有可能将原始文章发布到服务中,以便将其转发到服务器。如果我只是能够做到这一点,那么我的脚本就可以正常工作。 –
我编辑了我的回复,原帖需要你实现'IHttpModule'。看一看。 – nunespascal
谢谢。为你的时间。我发现这个解决方案非常有用: http://www.codeproject.com/Articles/31329/Simple-Reverse-Proxy-in-C-2-0-description-and-depl 我只需要下载演示给你一个dll和一个webconfig。我会在我原来的问题中提供更确切的信息。谢谢 –