How to read HTTP request headers in a WCF web service?

前端 未结 2 1234
囚心锁ツ
囚心锁ツ 2020-12-05 04:10

In a WCF web service, how does one read an HTTP/HTTPS request header? In this case, i\'m trying to determine the original URL host the client used. This might be in the X-Fo

相关标签:
2条回答
  • 2020-12-05 04:50

    Try WebOperationContext.Current.IncomingRequest.Headers

    I use following codes to see all headers :

    IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
    WebHeaderCollection headers = request.Headers;
    
    Console.WriteLine("-------------------------------------------------------");
    Console.WriteLine(request.Method + " " + request.UriTemplateMatch.RequestUri.AbsolutePath);
    foreach (string headerName in headers.AllKeys)
    {
      Console.WriteLine(headerName + ": " + headers[headerName]);
    }
    Console.WriteLine("-------------------------------------------------------");
    
    0 讨论(0)
  • 2020-12-05 04:51

    This is how I read them in one of my Azure WCF web services.

    IncomingWebRequestContext woc = WebOperationContext.Current.IncomingRequest;
    
    string applicationheader = woc.Headers["HeaderName"];
    
    0 讨论(0)
提交回复
热议问题