Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

apex_web_service.make_rest_request: Passing parameters and the content type

trentOct 13 2012 — edited Oct 31 2012
Not sure if I am missing something, but should this API be setting the content type (to application/x-www-url-formencoded) when there are values present for the parameters p_parm_name and p_parm_value.

The example in the docs is to a yahoo API. I'm not sure about that particular one (see: http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21676/apex_web_service.htm#BABEDJHJ), and I think it requires an appid (yahoo account), so i just went with the example here:

http://developer.yahoo.com/yql/guide/yql-code-examples.html#yql_php

If I run the following from a html file on my desktop it works:
<form method="POST" action="http://query.yahooapis.com/v1/public/yql">

<input type="hidden" name="q" value="select * from upcoming.events where location='San Francisco' and search_text='dance'"></input>
<input type="hidden" name="format" value="json"></input>
<input type="submit"></input>

</form>
That is, it returns a JSON result.

The raw HTTP data is as follows:
POST http://query.yahooapis.com/v1/public/yql HTTP/1.1
Host: query.yahooapis.com
Connection: keep-alive
Content-Length: 110
Cache-Control: max-age=0
Origin: null
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.11 (KHTML, like Gecko) Ubuntu/12.04 Chromium/20.0.1132.47 Chrome/20.0.1132.47 Safari/536.11
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-AU,en;q=0.8,en-US;q=0.6
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

q=select+fromupcoming.events+where+location%3D%27San+Francisco%27+and+search_text%3D%27dance%27&format=json>

However, running the following returns nothing: (nothing, as in nothing that depends on the parameters passed in)
set serveroutput on

declare

l_c CLOB;

begin


  l_c := apex_web_service.make_rest_request(
    p_url => 'http://query.yahooapis.com/v1/public/yql',
    p_http_method => 'POST',
    p_parm_name => apex_util.string_to_table('q:format'),
    p_parm_value => apex_util.string_to_table('select * from upcoming.events where location=''San Francisco'' and search_text=''dance'':json'),
    p_proxy_override => 'http://192.168.1.3:8888');

  dbms_output.put_line(substr(l_c, 1, 4000));

end;
Raw HTTP data:
POST http://query.yahooapis.com/v1/public/yql HTTP/1.1
Host: query.yahooapis.com
Connection: Keep-Alive
Content-Length: 106
Connection: close

q=select+%2A+from+upcoming%2Eevents+where+location%3D'San+Francisco'+and+search_text%3D'dance'&format=json>

I do note a key difference is that content type isn't being set in the web service API.

This was just to test a public service. I do note that the above has slighty different request data (percentage encoding on some chars). However, I experienced the same behaviour on a procedure I had written (I can also provide this example test case if you like), which is where I first noticed the issue.

Using utl_http and setting the content type to application/x-www-url-formencoded, does resolve the issue. However, just thought i'd see the possibility of using the Web service API that is made available.

Is the example in the docs valid, or am I missing something obvious?

This is on ApEx 4.1 on the OTN Dev Days VM.

Thoughts?
This post has been answered by J-Lig on Oct 31 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 28 2012
Added on Oct 13 2012
4 comments
7,237 views