Using an IP address in a URL

Content Platform Tenant Management Help

Version
9.7.x
File Size
4269 KB
Audience
anonymous
Part Number
MK-95HCPH002-19

Because you need to provide a hostname that includes the tenant and namespace names in all REST API requests, using the hostname is the simplest way to access a namespace. In some applications, however, using IP addresses may be more efficient than using the hostname.

If you use an IP address in the URL, you provide the hostname in an HTTP Host header.

In curl commands, you use the -H option and specify a Host header with the namespace name, tenant name, and domain name of the HCP system, in this format:

-H"Host:namespace-name.tenant-name.hcp-domain-name"

This example shows a complete curl command that uses an IP address:

curl -iT Q1_2012.ppt -k
    -H "Authorization: HCP bXl1c2Vy:3f3c6784e97531774380db177774ac8d”
    -H "Host: finance.europe.hcp.example.com"
    "https://192.168.130.14/rest/quarterly_rpts/Q1_2012.ppt"

In Python with PycURL, you specify an HTTPHEADER option, in this format:

curl.setopt(pycurl.HTTPHEADER, ["Host: namespace-name.
  tenant-name.hcp-domain-name"])

In the preceding syntax, the left and right brackets ([]) and parentheses (()) are part of the command and do not indicate optional or required components.

This example shows a Python script that uses an IP address:

import pycurl
import os
filehandle = open("Q1_2012.ppt", 'rb')
curl = pycurl.Curl()
curl.setopt(pycurl.URL,
  "https://192.168.125.125/rest/quarterly_rpts/Q1_2012.ppt")
curl.setopt(pycurl.HTTPHEADER, ["Authorization: HCP
  bXl1c2Vy:3f3c6784e97531774380db177774ac8d", "Host: finance.europe.hcp.example.com"])
curl.setopt(pycurl.SSL_VERIFYPEER, 0)
curl.setopt(pycurl.SSL_VERIFYHOST, 0)
curl.setopt(pycurl.UPLOAD, 1)
curl.setopt(pycurl.INFILESIZE, os.path.getsize("Q1_2012.ppt"))
curl.setopt(pycurl.READFUNCTION, filehandle.read)
curl.perform()
print curl.getinfo(pycurl.RESPONSE_CODE)
curl.close()
filehandle.close()