dongliang1996 2011-07-25 11:15
浏览 34

为什么file_get_contents()返回“应用程序错误”?

I have a simple code:

$t = file_get_contents("http://sub.example.com/list?u=test&passw=12345");

If I print that result I get "Application Error" text.

I really don't understand the reason, if I try to open that url on the browser i see it perfectly.

It returns "application/json" data.

  • 写回答

1条回答 默认 最新

  • dongpao9437 2011-07-25 11:20
    关注

    It is possible that the web application at sub.example.com expects some additional input apart from what goes into the URL (e.g. a cookie), does not find this input, and errors out.

    In any case, it's certain that the HTTP requests generated by (a) your program and (b) your browser are not identical, otherwise the application would exhibit the same behavior in both cases.

    To debug this, you can do the following:

    • Rewrite the code to use cURL instead of file_get_contents, so that you can specify an HTTP proxy
    • Install Fiddler, a fantastic HTTP debugging proxy
    • Pass the HTTP request your application generates and one given manually through the browser through Fiddler
    • Find the differences (you can simply do a text compare on the requests), this will lead you to the answer
    评论

报告相同问题?

悬赏问题

  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计