Tag: http headers

在c#中欺骗主机请求网页

我需要创建一个发送到我们网站的网页请求,但我也需要能够设置主机头信息。 我已经使用HttpWebRequest尝试了这个,但是Header信息是只读的(至少它的主机部分是)。 我需要这样做,因为我们想在用户可以之前执行页面的初始请求。 我们有10个负载均衡的Web服务器,因此我们需要从每个Web服务器请求该文件。 我尝试过以下方法: HttpWebRequest request = (HttpWebRequest)WebRequest.Create(“http://192.168.1.5/filename.htm”); request.Headers.Set(“Host”, “www.mywebsite.com”); WebResponse response = request.GetResponse(); 显然这不起作用,因为我无法更新标题,我不知道这是否确实是正确的方法。

如何向WCF服务添加跨域支持

我正在尝试允许来自我在localhost:80托管的javascript应用程序的POST请求到托管在不同端口的WCF REStful服务,但不知何故它不起作用。 我已经尝试在标题中添加自定义属性,并在我的服务的JSONData方法中以编程方式添加它,但我仍然在我的响应中得到’405 Method not allowed’。 这里适当的方法是什么? 这是我的界面: namespace RestService { public class RestServiceImpl : IRestServiceImpl { #region IRestServiceImpl Members public string JSONData() { HttpContext.Current.Response.AddHeader(“Access-Control-Allow-Origin”, “*”); return “Your POST request”; } #endregion } } 和服务代码: using System.ServiceModel; using System.ServiceModel.Web; using System.Web.Script.Services; namespace RestService { [ServiceContract] public interface IRestServiceImpl { [OperationContract] [ScriptMethod] [WebInvoke(Method = “POST”, ResponseFormat […]

HTTP发布C#中的XML数据

我需要HTTP将XML数据发布到具有名称为XMLdata的Textarea的URL。 我的XMl数据已准备就绪,位于XDocument Sendingxml = xml中; 但是我试过的邮政编码不起作用。 主要是因为我不知道如何将XML数据放在postData变量中,因为它只接受字符串。 这是我的代码: XDocument Sendingxml = xml; // string Sendingxml = ” 5 CrosskeyCaliforniaCA92620Condo456432013070100158346681a598cf23f412095f6092c281823e611160 “; // Create a request using a URL that can receive a post. WebRequest request = WebRequest.Create(“https://test.bluebookcva.net/order/testdirectplugin/3”); // Set the Method property of the request to POST. request.Method = “POST”; // Create POST data and convert […]