Home » SQL & PL/SQL » SQL & PL/SQL » Response in JSON format (Oracle , 12C, windowns)
Response in JSON format [message #648777] Thu, 03 March 2016 05:11 Go to next message
sunilreddy
Messages: 37
Registered: September 2011
Location: Hyderabad
Member
Hi Gurus,

Please see below code, am able to call the webservice with JSON content but not able to get the response in JSON format,geting in XML format can any one help on this.

declare
http_req utl_http.req;
http_resp utl_http.resp;
request_env VARCHAR2(32767);
response_env VARCHAR2(32767);
l_auth_url VARCHAR2(32767) := 'api url';
begin
dbms_output.put_line('strating request');
request_env:= '<{'
||'"requestPayload"'
||'{'
||'"userid": "userid"'
||'"password": "password"'
||'"realm": "realm"'
||'}'
||'}';

dbms_output.put_line('begin request');
UTL_HTTP.set_wallet('file:E:\app\oracle\DB11G\wallet', 'walletpwd');
http_req := utl_http.begin_request(l_auth_url,'POST',utl_http.HTTP_VERSION_1_1);

utl_http.set_transfer_timeout (120);

dbms_output.put_line('setting headers');
utl_http.set_header(http_req, 'Content-Type', 'application/json');
utl_http.set_header(http_resp, 'Accept', 'application/json');
dbms_output.put_line('writing text');

utl_http.write_text(http_req, request_env);

http_resp := utl_http.get_response(http_req);
--utl_http.set_header(http_req, 'Accept-Charset', 'application/json; charset=utf-8');
utl_http.read_text(http_resp, response_env);


dbms_output.put_line('Status code: '|| response_env);
dbms_output.put_line('Status code: ' || http_resp.status_code);
dbms_output.put_line('Reason phrase: ' || http_resp.reason_phrase);

utl_http.end_response(http_resp);
exception
when others then
dbms_output.put_line(sqlcode ||' ' ||sqlerrm);
end;
/

[Updated on: Thu, 03 March 2016 05:12]

Report message to a moderator

Re: Response in JSON format [message #648783 is a reply to message #648777] Thu, 03 March 2016 06:13 Go to previous messageGo to next message
Michel Cadot
Messages: 68773
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

Maybe because your web service returns an XML and not a JSON?

Re: Response in JSON format [message #648786 is a reply to message #648783] Thu, 03 March 2016 06:20 Go to previous messageGo to next message
sunilreddy
Messages: 37
Registered: September 2011
Location: Hyderabad
Member
No, they are sending JSON only. am geting output in HTML format.
Re: Response in JSON format [message #648787 is a reply to message #648786] Thu, 03 March 2016 06:24 Go to previous message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
https://www.google.com/webhp?hl=en&tab=ww#hl=en&q=oracle+call+webservice+json
Previous Topic: Print 1 .. 100 numbers using Dual table in SQL statement
Next Topic: Compile an object by oracle command for first time
Goto Forum:
  


Current Time: Wed Dec 31 16:02:56 CST 2025