W7 Pro IIS 7.5 overwrites PHP Location: Header

前端 未结 3 522
日久生厌
日久生厌 2021-01-05 18:30

I am creating a RESTful API in PHP, and have encountered a problem. When the client is posting data to the server, the server should return:

Status code 201          


        
3条回答
  •  南方客
    南方客 (楼主)
    2021-01-05 18:53

    The solution was to create an IIS module, that rewrites the header "Custom-Location" to "Location" after FastCGI is done.

    Then, FastCGI won't know that we are sending a Location header at all, and it won't modify my response.

    The module:

    string Location = context.Response.Headers["Custom-Location"] as string;
    if (!string.IsNullOrEmpty(Location))
    {
        context.Response.Headers.Remove("Custom-Location");
        context.Response.AddHeader("Location", Location);
    }
    

    PHP:

    header("Custom-Location: http://google.no",true,201);
    header("Content-Type: application/xml");
    echo "";
    

    (still dummy code, not extremly correct code :) )

提交回复
热议问题