1

I am trying to write a PL/SQL procedure that connects to a vendor server and transfer some student data.

I have been using UTL_HTTP with no success.

Below is my UTL_HTTP cpde. I cut most of the data for easier read.

    var_data_body :='input_data=[{"School ID*":"B10011122","Class Code*":"MATH101","Location*":"CLB223"}, 
    {"School ID*":"B20022233","Class Code*":"BIOL101","Location*":"CLB123"}]';

    var_body_combine:= 'input_type=JSON '||var_data_body ||
                        ||' drop_not_passed_enrollments=false '
                        ||' dry_run=true '; 
    var_body_length:= LENGTH(var_body_combine);

    const_http_request := UTL_HTTP.BEGIN_REQUEST (temp_new_url, const_POST_method);
    utl_http.set_header(const_http_request, 'Content-Type', 'application/x-www-form-urlencoded');
    utl_http.set_header(const_http_request, 'Content-Length',var_body_length);
    UTL_HTTP.set_header(const_http_request, 'Authorization','Bearer '|| var_token);  --this is vendor authorization token that I got from earlier handshake process.
    UTL_HTTP.set_header(const_http_request, 'X-TW-PersonId',const_userid);  --this is my user_id

    UTL_HTTP.write_text(const_http_request, var_body_combine);

    DBMS_OUTPUT.put_line ('My full var_body is: '||var_body_combine);
      
    const_http_response := UTL_HTTP.GET_RESPONSE (const_http_request);


Vendor server gives me generic error message that they can not process my request. I asked a vendor representative to upload the data body part and they said they can upload my data just fine. I am thinking there is something I did wrong in the syntax.

I have been experimenting by separating the body into different line(or adding/removing that data-urlencode), like below. But still gives me error. Some steps that I did even give me Bad Request error message.

    UTL_HTTP.write_text(const_http_request, '--data-urlencode input_type=JSON');
    UTL_HTTP.write_text(const_http_request, '--data-urlencode '|| var_data_body );
    UTL_HTTP.write_text(const_http_request, '--data-urlencode drop_not_passed_enrollments=false');
    UTL_HTTP.write_text(const_http_request, '--data-urlencode dry_run=true');   

I read some documentation about UTL_HTTP and am not sure what I miss since some examples are pretty straightforward.

Has anyone ever worked with similar process before?

Any insight is appreciated.

Thank you.

brown_rice
  • 11
  • 1
  • It could be something with related to the content type you are passing. Please have a look at https://stackoverflow.com/questions/44393679/how-to-sent-a-post-request-with-form-data-and-parameters-in-pl-sql – Sujitmohanty30 Sep 11 '20 at 16:53

0 Answers0