dongnaoben4456 2018-07-05 14:28
浏览 54
已采纳

使用HTTP GET方法检索PHP脚本

(I'm a beginner. This is to understand PHP better.)

While experimenting with HTTP I was trying to GET a PHP-file from my server and I didn't get anything. Neither the HTTP-Header Content-Length nor any content is available for reading in the response.

string url = "http://php.net/sites.php";
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
request.AutomaticDecompression = DecompressionMethods.GZip;
request.Method = "GET";
Stream stream = request.GetRequestStream(); // "ProtocolViolationException" is thrown here
StreamWriter writer = new StreamWriter(stream);
writer.WriteLine("test 3");

So with that C# code above and with my local IIS i can't GET any php files right? I can GET only html, js, css, images and a few_other right? What I found out as well is if I want the PHP script to be executed I need to change "GET" to "POST" and then I will be getting the PHP output.

What I would like to understand:

  • There is no way for me with common Web-Servers to retrieve PHP code?
  • Webbrowsers do POST-requests automatically when retrieving php output?
  • Why is it like this?

FYI: (not important here) I have to write C# app later that is going to communicate to a WebServer to retrieve some data and do actions that Webbrowsers can't do.

  • 写回答

1条回答 默认 最新

  • dtz63853 2018-07-05 14:52
    关注

    So with that C# code above and with my local IIS i can't GET any php files right?

    If you statically host the php files you can get them from your server but this would be unusual indeed.

    I can GET only html, js, css, images and a few_other right?

    You can get whatever content that your server is sending, in this case IIS is receiving your GET request and deciding what to do with it.

    There is no way for me with common Web-Servers to retrieve PHP code?

    If you set up your own server to host the php files as static content then you can see your own php files. There is no way to see other's PHP source files unless their server is configured similarly.

    Webbrowsers do POST-requests automatically when retrieving php output?

    Browsers do get and post. Browsers GET when you type something into the address bar and POST when you submit a form.

    Why is it like this?

    PHP is a server side language, exposing the code is a huge security risk. This is also code that must execute on the server so there is no point in the client side (browser) seeing the code that is on the server except for potential debugging purposes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题