在oracle中通过utl_http获得指定网页内容

SET serveroutput ON SIZE 40000

DECLARE
  v_text varchar2(100) := '试验%S已ok';--不能有空白
  req    utl_http.req;
  resp   utl_http.resp;
  value  VARCHAR2(1000);

BEGIN
  v_text := replace(v_text,'%','%25');
  v_text := replace(utl_encode.text_encode(v_text), '=', '%');
  req    := utl_http.begin_request('http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=' ||
                                   v_text || '&langpair=zh|en');
  resp   := utl_http.get_response(req);
  LOOP
    utl_http.read_line(resp, value, TRUE);
    value := replace(value,'% S','%S');
    value := replace(value,'{"responseData": {"translatedText":"','');
    value := replace(value,'"}, "responseDetails": null, "responseStatus": 200}','');
    dbms_output.put_line(value);
  END LOOP;
  utl_http.end_response(resp);
EXCEPTION
  WHEN utl_http.end_of_body THEN
    utl_http.end_response(resp);
END;

你可能感兴趣的:(oracle,Ajax)