dqby43944 2010-04-23 21:01
浏览 29
已采纳

如何通过PHP代理发送标头?

Okay, so I have an issue with an AJAX request. I currently have this URL:

http://www.google.com/images?hl=en&safe=off&gbv=2&tbs=isch%3A1&sa=1&q=cars+imagesize%3A500x500&aq=f&aqi=&aql=&oq=&gs_rfai=&start=0

I then pass it to my proxy script by modifying the string to this:

proxy.php?url=http://www.google.com/images?hl=en&safe=off&gbv=2&tbs=isch%3A1&sa=1&q=cars+imagesize%3A500x500&aq=f&aqi=&aql=&oq=&gs_rfai=&start=0

I need to use the PHP proxy script to grab that page's HTML so that I can then parse through it with javascript. However, the problem is that the headers in that URL are also being sent to the proxy script, and as a result, I get a 'malformed or illegal request' error. I'm pretty sure the two different sets of headers are the problem, because if I just replace the original URL string with 'http://wwww.google.com', the proxy returns the HTML of the page correctly.

So basically, I don't know how to fix this. I'm a complete PHP noob, and I tried escaping the original URL before I appended it to the 'proxy.php?url=', but that doesn't fix anything. Any ideas?

Thanks!

  • 写回答

1条回答 默认 最新

  • dongmangji0950 2010-04-23 21:57
    关注

    Figured it out- you need to use encodeURIComponent() on the original URL string before you append it to the proxy string.

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

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序