我正在构建一个仅通过反向代理使用外部API的js-webapp。
为此,我设置了Apache,添加了以下规则:
ProxyRequests off
ProxyPassReverseCookiePath /starmobile /
<Location /api/>
ProxyPass http://209.90.224.106:7500/starmobile/
ProxyPassReverse http://209.90.224.106:7500/starmobile/
</Location>
<Proxy *>
Order deny,allow
Allow from all
Satisfy all
</Proxy>
这样,所有对/ api /的请求都代理到api服务器,让所有其他请求在本地处理(从而允许加载静态资源和js)。
当使用curl通过代理执行请求时,一切正常:
curl -d "{\"method\":\"getAllItemClasses\"}" http://starcom/api/AvailabilityWebMobile/
[{"code":"Default","id":999},{"code":"06KALANCHOE","id":100041},{"code":"06BEGONIA","id":100043},{"code":"06ROSES","id":100045},{"code":"04AFRICANVIOLET","id":100046},{"code":"04CYCLAMEN","id":100047},{"code":"04ROSES","id":100048},{"code":"04ASST","id":100049},{"code":"04BEGONIA","id":100050},{"code":"04MUM","id":100051},{"code":"04KALANCHOE","id":100052},{"code":"04GERBERA","id":100053},{"code":"04PRIMROSE","id":100054},{"code":"06AZALEA","id":100055},{"code":"06CYCLAMEN","id":100056},{"code":"06MUM","id":100057},{"code":"06GERBERA","id":100058},{"code":"06HYDRANGEA","id":100059},{"code":"06ASST","id":100060},{"code":"06TULIP","id":100063},{"code":"06HYACINTH","id":100064},{"code":"06EASTERLILY","id":100065},{"code":"06SHAMROCK","id":100070},{"code":"045SHAMROCK","id":100071},{"code":"05DAHLIA","id":100194},{"code":"05OSTEO","id":100195},{"code":"06DUTCH BULBS","id":100263},{"code":"06WAVE","id":100304},{"code":"18PKWAVE","id":100305},{"code":"PTWAVE","id":100306},{"code":"2.6QTWAVE","id":100307},{"code":"16.5CLASSICA","id":100308},{"code":"10SQTBISCOTTO","id":100309},{"code":"10TALLBISCOTTO","id":100310},{"code":"13VALLEY","id":100311},{"code":"14COCOHB","id":100312},{"code":"14.5CONTESSA","id":100313},{"code":"PGR","id":100398},{"code":"FERTILIZER","id":100399},{"code":"POTS","id":100409},{"code":"SHUTTLE","id":100410},{"code":"TRAY","id":100411},{"code":"INSERT","id":100412},{"code":"FLAT","id":100413}]
然而,当通过ajax执行相同的请求时,我得到状态代码200 OK,但是空身。 Firebug显示红色的200 OK消息,但是没有更多说明,Chrome只是在状态上显示“(已取消)”消息(尽管细节识别出响应标题是200)。
我完全迷失了为什么我没有得到身体,因为代理应该防止诸如使用相同的域名政策之类的问题....
我附上了Chrome显示的响应标题:
Connection:Keep-Alive
Content-Encoding:gzip
Content-Type:application/json;charset=UTF-8
Date:Wed, 15 Jun 2011 13:03:46 GMT
Keep-Alive:timeout=15, max=100
Server:Apache-Coyote/1.1
Transfer-Encoding:chunked
Via:1.1 starcom
提前致谢