Hi,
Im trying to get a response of a navision web service but always get the error 400. I have tried several ways to send the request but always get the same status error 400. If I use chrome with the widzler extension, works perfectly passing the item number to read.
l_string_request example 1:
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<Read xmlns="urn:microsoft-dynamics-schemas/page/read_item">
<No>' || l_no || '</No>
</Read>
</Body>
</Envelope>
l_string_request 2 example 2:
<Soap:Envelope xmlns:Soap="http://schemas.xmlsoap.org/soap/envelope/">
<Soap:Body>
<Read xmlns="urn:microsoft-dynamics-schemas/page/read_item">
<No>' || l_no || '</No>
</Read>
</Soap:Body>
</Soap:Envelope>
This is the response from the ws:
Response> status_code: "400"
Response> reason_phrase: "Bad Request"
Response> http_version: "HTTP/1.1"
Response> length: "311"
=== Print first 20 lines of HTTP response... ===
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<Read xmlns="urn:microsoft-dynamics-schemas/page/read_item">
<No>8464094545884</No>
</Read>
</Body>
</Envelope>
[00]: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""
[01]: http://www.w3.org/TR/html4/strict.dtd">
<HTML><HE
[02]: AD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="C
[03]: ontent-Type" Content="text/html; charset=us-ascii"
[04]: ></HEAD>
<BODY><h2>Bad Request</h2>
<hr><p>HTTP
[05]: Error 400. The request is badly formed.</p>
</BOD
[06]: Y></HTML>
Code:
DECLARE
l_http_request UTL_HTTP.req;
l_http_response UTL_HTTP.resp;
l_buffer_size NUMBER(10) := 1024;
l_line_size NUMBER(10) := 50;
l_lines_count NUMBER(10) := 20;
l_string_request VARCHAR2(1024);
l_line VARCHAR2(128);
l_substring_msg VARCHAR2(1024);
l_raw_data RAW(1024);
l_clob_response CLOB;
l_xml_encoding VARCHAR2(128) := 'UTF-8';
l_no VARCHAR2(128) := '8464094545884';
BEGIN
l_string_request := '<Soap:Envelope xmlns:Soap="http://schemas.xmlsoap.org/soap/envelope/">
<Soap:Body>
<Read xmlns="urn:microsoft-dynamics-schemas/page/read_item">
<No>'|| l_no ||'</No>
</Read>
</Soap:Body>
</Soap:Envelope>';
UTL_HTTP.set_transfer_timeout(60);
l_http_request := UTL_HTTP.begin_request(url => 'http://USER:PASS@10.212.2.100:7047/NAV/WS/TEST,%20S.A/Page/Read', method=>'POST', http_version => 'HTTP/1.1');
UTL_HTTP.set_header(l_http_request, 'User-Agent', 'Mozilla/4.0');
UTL_HTTP.set_header(l_http_request, 'Connection', 'close');
UTL_HTTP.set_header(l_http_request, 'Content-Type', 'text/xml;charset='||l_xml_encoding);
UTL_HTTP.set_header(l_http_request, 'Content-Length', LENGTHB(l_string_request));
UTL_HTTP.set_header( l_http_request, 'Transfer-Encoding', 'chunked');
UTL_HTTP.set_body_charset( l_http_request, l_xml_encoding);
<<request_loop>>
FOR i IN 0..CEIL(LENGTH(l_string_request) / l_buffer_size) - 1 LOOP
l_substring_msg := SUBSTR(l_string_request, i * l_buffer_size + 1, l_buffer_size);
BEGIN
l_raw_data := UTL_RAW.cast_to_raw(l_substring_msg);
UTL_HTTP.write_raw(r => l_http_request, data => l_raw_data);
DBMS_OUTPUT.put_line('Buffer> "' || UTL_RAW.cast_to_varchar2(l_raw_data) || '"');
EXCEPTION
WHEN NO_DATA_FOUND THEN
EXIT request_loop;
END;
END LOOP request_loop;
l_http_response := UTL_HTTP.get_response(l_http_request);
DBMS_OUTPUT.put_line('Response> status_code: "' || l_http_response.status_code || '"');
DBMS_OUTPUT.put_line('Response> reason_phrase: "' ||l_http_response.reason_phrase || '"');
DBMS_OUTPUT.put_line('Response> http_version: "' ||l_http_response.http_version || '"');
BEGIN
<<response_loop>>
LOOP
UTL_HTTP.read_raw(l_http_response, l_raw_data, l_buffer_size);
l_clob_response := l_clob_response || UTL_RAW.cast_to_varchar2(l_raw_data);
END LOOP response_loop;
EXCEPTION
WHEN UTL_HTTP.end_of_body THEN
UTL_HTTP.end_response(l_http_response);
END;
DBMS_OUTPUT.put_line('Response> length: "' || LENGTH(l_clob_response) || '"');
DBMS_OUTPUT.put_line(CHR(10) || '=== Print first ' || l_lines_count || ' lines of HTTP response... ===' || CHR(10) || CHR(10));
DBMS_OUTPUT.put_line(l_string_request);
<<print_response>>
FOR i IN 0..CEIL(LENGTH(l_clob_response) / l_line_size) - 1 LOOP
l_line := SUBSTR(l_clob_response, i * l_line_size + 1, l_line_size);
DBMS_OUTPUT.put_line('[' || LPAD(i, 2, '0') || ']: ' || l_line);
EXIT WHEN i > l_lines_count - 1;
END LOOP print_response;
exception when others then
dbms_output.put_line('sqlerrm: '||SQLERRM);
dbms_output.put_line('backtrace: '||DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
IF l_http_request.private_hndl IS NOT NULL THEN
UTL_HTTP.end_request(l_http_request);
END IF;
IF l_http_response.private_hndl IS NOT NULL THEN
UTL_HTTP.end_response(l_http_response);
END IF;
END;
/
I try differents configurations and always get the same result, Error 400. The request is badly formed.
Any help y highly appreciated.
Thanks.