Upon URL Redirection UTL_HTTP Call gets Bad Request (HTTP_BAD_REQUEST) Response From Web Service

(Doc ID 2402308.1)

Last updated on MAY 28, 2018

Applies to:

PL/SQL - Version 12.2.0.1 and later
Information in this document applies to any platform.

Symptoms

A web service call is made using the UTL_HTTP and the web server re-directs the URL to some other server. In this scenario, the UTL_HTTP call gets HTTP_BAD_REQUEST as response from the web server.

Generating 10937 trace at level 4 shows that upon redirection, the UTL_HTTP calls adds the host name twice when re-sending the request header. For example, this is how the trace looks like

nhp: 2017-11-06 10:52:29.359755 connect enter dummyhost.oracle.com:80                                                 >>>>> UTL_HTTP Calling dummyhost.oracle.com:80
nhp: 2017-11-06 10:52:29.363521 connect return 0x7f79bed4b070 0 0 elapsed +0 00:00:00.003766
nhp: > GET /redirectme/ HTTP/1.1
nhp: > Host: dummyhost.oracle.com
nhp: > Connection: close
nhp: >
nhp: 2017-11-06 10:52:29.363682 send enter 0x7f79bed4b070 73
nhp: > send 73 bytes
GET /redirectme/ HTTP/1.1
Host: dummyhost.oracle.com
Connection: close

[end]
...
...
...
nhp: < recv 550 bytes
HTTP/1.1 301 Moved Permanently                                                                                                              >>>>> Gets response as 301 which indicates URL Re-Direction
Date: Mon, 06 Nov 2017 10:53:26 GMT
Server: XXXXXXXXXXXXXXXX
Location: http://dummyhost.oracle.com/ivebeenredirected/
Content-Length: 251
Connection: close
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://dummyhost.oracle.com/ivebeenredirected/">here</a>.</p>
</body></html>
[end]
nhp: < HTTP/1.1 301 Moved Permanently
nhp: < Date: Mon, 06 Nov 2017 10:53:26 GMT
nhp: < Server: XXXXXXXXXXXXXXXX
nhp: < Location: http://dummyhost.oracle.com/ivebeenredirected/
nhp: < Content-Length: 251
nhp: < Connection: close
nhp: < Content-Type: text/html; charset=iso-8859-1
nhp: <
...
...
...
nhp: > GET /ivebeenredirected/ HTTP/1.1
nhp: > Host: dummyhost.oracle.com                                                                                                          >>>>> Host name is added twice to the request header
nhp: > Host: dummyhost.oracle.com                                                                                                          >>>>> Host name is added twice to the request header
nhp: > Connection: close
nhp: >
nhp: 2017-11-06 10:52:29.368633 send enter 0x7f79bed4b070 105
nhp: > send 105 bytes
GET /ivebeenredirected/ HTTP/1.1
Host: dummyhost.oracle.com                                                                                                 
Host: dummyhost.oracle.com
Connection: close

[end]

As result of wrong request header the UTL_HTTP call gets HTTP_BAD_REQUEST from the web server.

Changes

Nothing specific in Oracle end but there may be configuration changes in the web server end. 

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms