私がやろうとしているのは、API をプロキシとして使用することです。それは Fiddler で動作し、アイデアがありました。
私は Web サイトを持っていて、別の Web サイトを iframe に表示したいと考えています。しかし、それを行うには「no-open」ヘッダーを削除する必要があります。
したがって、計画は次のとおりです。私のサイトから API に URL 文字列を送信すると、API はその URL にリクエストを送信し、応答を取得します。ページを保存せずに、いくつかのヘッダーを変更して Web サイトに応答します。
問題: json を返し続けます。HTML コードを文字列として返そうとしましたが、私の Web サイトはそれを iframe にレンダリングしません。
これは私のコードです。
public class ProductsController : ApiController
{
public HttpWebResponse GetProductsByCategory(string url, int edit)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = WebRequestMethods.Http.Get;
request.ContentType = "text/html";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//
if (edit == 1)
{
response.Headers.Set("Content-Disposition", "");
response.Headers.Set("X-Download-Options", "");
}
response.Headers.Set("Content-Type", "text/html");
response.Headers.Set("APIflag", "Hi!");
Stream theHTML = response.GetResponseStream();
StreamReader objReader = new StreamReader(theHTML);
string myHTML = objReader.ReadToEnd();
System.Diagnostics.Debug.WriteLine("url was: "+url); //is OK
System.Diagnostics.Debug.WriteLine("edit flag was: " +edit); //is OK
System.Diagnostics.Debug.WriteLine(myHTML); //is OK
return response;
}
}