Web request property “URL” is empty

流过昼夜 提交于 2020-01-25 01:44:17

问题


I'm trying to figure out how to read the full URI from a request (Web.HTTPApp.TWebRequest). There is a URL property, however it returns empty, and I don't see any more properties which could give me this. How can I get the complete URI of the request? This is being used via Indy 10 TIdHTTPWebBrokerBridge.

For example...

http://www.mydomain.com:18500/SomePath/SomeFile.html?n=v&a=b

I tried tracking this URL property and found that in IdHTTPWebBrokerBridge.pas this is being left blank, apparently deliberately...

function TIdHTTPAppRequest.GetStringVariable(Index: Integer): AnsiString;
...
  case Index of
    ...
    //INDEX_URL             : Result := AnsiString(FRequestInfo.Document);
    INDEX_URL             : Result := AnsiString(''); // Root - consistent with ISAPI which return path to root 

回答1:


I don't know why INDEX_URL returns a blank string. Obviously, it was deliberate, though.

If you look at the IdHTTPWebBrokerBridge.pas code more carefully, you will see that INDEX_URL used to return FRequestInfo.Document, which is the same value that INDEX_PathInfo and INDEX_PathTranslated both return. So you could try using a combination of the TWebRequest.Host, TWebRequest.ServerPort, TWebRequest.Path..., and TWebRequest.Query properties to recreate the URL you are looking for (minus the protocol, which you will just have to hard-code).

Also, XE+ has a TWebRequest.RawPathInfo property which TIdHTTPAppRequest implements to return Indy's TIdHTTPRequestInfo.URI property value, so you should look at that as well.



来源:https://stackoverflow.com/questions/17731304/web-request-property-url-is-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!