我正在谷歌应用引擎上的php中进行eBay搜索API调用findItemsByKeywords
。它在本地工作,而不是GAE。这就是我打电话的方式
$resp = simplexml_load_file($apicall);
我检查了主机提供已启用PHP打开URL,因为文件ini_get('allow_url_fopen')
返回1.
只有在GAE上运行时,我才会在$ resp中获取null。
编辑:
这是GAE错误日志中的内容。
2014-06-12 16:21:50 Running command: "['C:\\Python27\\pythonw.exe', 'C:\\google-cloud-sdk\\bin\\dev_appserver.py', '--skip_sdk_update_check=yes', '--port=10080', '--admin_port=8002', 'C:\\app_engine\\invApp']"
INFO 2014-06-12 16:21:53,055 devappserver2.py:716] Skipping SDK update check.
WARNING 2014-06-12 16:21:53,076 api_server.py:378] Could not initialize images API; you are likely missing the Python "PIL" module.
INFO 2014-06-12 16:21:53,099 api_server.py:171] Starting API server at: http://localhost:16086
INFO 2014-06-12 16:21:53,107 dispatcher.py:182] Starting module "default" running at: http://localhost:10080
INFO 2014-06-12 16:21:53,111 admin_server.py:117] Starting admin server at: http://localhost:8002
INFO 2014-06-12 16:22:01,536 module.py:639] default: "GET / HTTP/1.1" 200 1637
INFO 2014-06-12 16:22:01,566 module.py:639] default: "GET /static/main.css HTTP/1.1" 200 206
INFO 2014-06-12 16:22:01,568 module.py:639] default: "GET /static/script.js HTTP/1.1" 304 -
ERROR 2014-06-12 16:22:01,566 module.py:714] Request to '/static/main.css' failed
Traceback (most recent call last):
File "C:\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\module.py", line 710, in _handle_request
return handler.handle(match, environ, wrapped_start_response)
File "C:\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\static_files_handler.py", line 369, in handle
return self._handle_path(full_path, environ, start_response)
File "C:\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\static_files_handler.py", line 182, in _handle_path
start_response('200 OK', headers)
File "C:\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\module.py", line 640, in wrapped_start_response
return start_response(status, response_headers, exc_info)
File "C:\google-cloud-sdk\platform\google_appengine\lib\cherrypy\cherrypy\wsgiserver\wsgiserver2.py", line 2155, in start_response
raise TypeError("WSGI response header value %r is not of type str." % v)
TypeError: WSGI response header value u'text/css' is not of type str.
INFO 2014-06-12 16:22:01,571 module.py:639] default: "GET /static/main.css HTTP/1.1" 500 -
INFO 2014-06-12 16:22:11,984 module.py:639] default: "GET /api.php?target=ebay&searchClause=cake|3|4|true HTTP/1.1" 200 940
编辑:
我找到了解决方案。
我必须使用file_get_contents
,如果成功,请执行simplexml_load_string
。
出于某种原因,GAE不允许我使用simplexml_load_file
。
这是有效的代码。
$resp = file_get_contents($apicall);
if($resp){
$result = simplexml_load_string($resp);
}
exit(json_encode($result));
答案 0 :(得分:0)
从https://developers.google.com/appengine/docs/php/#PHP_Disabled_functions“您还必须在应用程序的启动脚本中的某处调用libxml_disable_entity_loader(false)以启用外部XML实体的加载。”