我試圖設置一個簡單的代理服務器,將數據發佈到我的代理服務器。代理服務器將把發佈的數據轉發給實際的服務器,並從實際的服務器獲得響應。然後在發出請求的網站所讀取的代理服務器上顯示響應並對數據執行任何操作。 我在第一部分獲取來自網站的原始發佈數據時遇到了問題。看起來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。我會在我原來的問題中提供更確切的信息。謝謝 –