获取UTL_HTTP响应代码400

时间:2017-09-21 15:18:50

标签: json post plsql

我正在创建一个oracle过程来使用POST请求调用REST API。但是,对于无效语法,我得到的响应代码为400。任何人都可以帮我解决我编写的代码出了什么问题

 CREATE OR REPLACE PROCEDURE p_cmhash( s VARCHAR2)
       AS
        req utl_http.req;
        res utl_http.resp;
        url varchar2(4000) := 'http://m037104:7001/DocumentManagementApi/qapi/bdm-documents';
        name varchar2(4000);
        buffer varchar2(32767):=NULL;
       content varchar2(32000) := '{ "dmType" : "B-S-ADMN", "indexes" : { "RECRUITER ID" : "*" } }';


      begin
        req := utl_http.begin_request(url, 'POST',' HTTP/1.1');
        utl_http.set_header(req, 'User-Agent', 'Mozilla/4.0');

          utl_http.set_authentication(req, 'TOM', 'u_pick_it');
          UTL_HTTP.set_header(req, 'Accept' , 'application/json');

          utl_http.set_header(req,'Content-Type','application/json; charset=utf-8');
         -- UTL_HTTP.SET_BODY_CHARSET('UTF-8');
          UTL_HTTP.set_header(req, 'Accept-Length'  ,length(content));

        utl_http.write_text(req, content);

        res := utl_http.get_response(req);

        IF (res.status_code = UTL_HTTP.HTTP_OK) THEN
           dbms_output.put_line('response is okay');
           ELSE
           dbms_output.put_line('RESPONSE CODE IS '||res.status_code);
        END IF;
        -- process the response from the HTTP call
        begin
          loop
            utl_http.read_line(res, buffer,TRUE);
            dbms_output.put_line('buffer-->'||buffer);
          end loop;


    utl_http.end_response(res);
    exception
      when utl_http.end_of_body
      then
        utl_http.end_response(res);
    end;
         END;

输出

响应代码是400

buffer-->{
buffer-->  "errors": 
buffer-->  [
buffer-->    {
buffer-->      "code": "Invalid.AppName.Request",
buffer-->      "message": "dmType:{0} is invalid.",
buffer-->      "description": "dmType:{0} is invalid."
buffer-->    }
buffer-->  ]enter code here
buffer-->}

0 个答案:

没有答案