我正在尝试使用UTL_HTTP调用Sonar删除项目API(不要问我为什么使用oracle包,我别无选择)。
我使用curl测试了我的命令,它运行正常:
curl -u c3b4gj1k11a12n726kjo0eaaf1d0035dt6afd7cg5d: -d "key=community.developer.scott" http://sonar:9000/api/projects/delete
但是当我尝试在PL / SQL中实现它时,我有一个内部服务器错误
declare
l_command varchar2(2500) := 'http://sonar:9000/api/projects/delete?key=community.developer.scott';
l_req UTL_HTTP.req;
l_response UTL_HTTP.resp;
begin
l_req := UTL_HTTP.begin_request(l_command, 'POST');
UTL_HTTP.SET_HEADER(l_req,'Authorization','Basic c3b4gj1k11a12n726kjo0eaaf1d0035dt6afd7cg5d');
l_response := UTL_HTTP.GET_RESPONSE(l_req);
if l_response.status_code != 200 then
display_msg('Error accessing to Sonar (error code: ' || l_response.status_code||')');
display_msg('HTTP response reason phrase: ' || l_response.reason_phrase);
end if;
UTL_HTTP.end_response(l_response);
exception
when others then display_msg('Http detailed sqlerrm: '|| utl_http.GET_DETAILED_SQLERRM());
end;
下面是服务器日志:
2017.11.20 17:55:44 ERROR web[o.s.s.ui.JRubyFacade] Fail to render: http://sonar:9000/api/projects/delete?key=community.developer.scott
undefined method `empty?' for nil:NilClass
C:/Program Files (x86)/Sonarqube/web/WEB-INF/lib/authenticated_system.rb:132:in `login_from_basic_auth'
org/jruby/RubyProc.java:290:in `call'
org/jruby/RubyProc.java:224:in `call'
C:/Program Files (x86)/Sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/http_authentication.rb:126:in `authenticate'
C:/Program Files (x86)/Sonarqube/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/http_authentication.rb:116:in `authenticate_with_http_basic'
C:/Program Files (x86)/Sonarqube/web/WEB-INF/lib/authenticated_system.rb:129:in `login_from_basic_auth'
C:/Program Files (x86)/Sonarqube/web/WEB
有人知道如何设置HTTP标头以使用令牌身份验证调用Sonar API吗?