public class HttpClient extends Object
| Modifier and Type | Field and Description |
|---|---|
protected HttpURLConnection |
m_httpCon
The
HttpURLConnection which was made by the client. |
protected URL |
m_url |
protected LinkedList<Attribute> |
reqPropertiesList |
| Constructor and Description |
|---|
HttpClient()
The construction initialize the post data
|
| Modifier and Type | Method and Description |
|---|---|
void |
addPostData(String postData)
Add Post Data
|
void |
appendRequestProperty(String name,
String value)
Append a request property, if the property already exists the value
given overrides the old value.
|
void |
disconnect()
Dissconnect the connection
|
String |
getCookie()
Get the cookie
|
URL |
getCurrentURL()
Return the url which the HttpClient object last retreived.
|
String |
getHeaderFieldKey(int pos)
after the
send() method was called , use this method to get the HTTP header name
by specifying the header position. |
int |
getReadTimeout() |
String |
getResponseBody()
after the
send() method was called , use this method to get the HTTP response
body text that was returned by the HTTP remote server. |
String |
getResponseHeader(int pos)
after the
send() method was called , use this method to get the HTTP header value
by specifying the header position. |
String |
getResponseHeader(String headerName)
after the
send() method was called , use this method to get the HTTP header value
by specifying the header name returned by the remote HTTP server. |
List<String> |
getResponseHeaders()
Return all the headers value in a list of String objects
|
InputStream |
getResponseInputStream()
return the entire server response in an
InputStream. |
int |
getStatusCode()
after the
send() method was called , use this method to get the HTTP status code
returned by the remote HTTP server. |
String |
getStatusMessage()
after the
send() method was called , use this method to get the HTTP status message
returned by the remote HTTP server. |
void |
openConnection(String url)
Opens a GET of PUT HTTP connection to a remote server
according the method which was set before, default is GET.
|
void |
openConnection(String method,
String url)
Opens a HTTP connection to a remote server
|
void |
openConnection(String method,
String url,
String username,
String password,
Properties sslProps)
Opens a HTTP connection to a remote server using basic authintication
|
void |
openConnectionServerCert(String method,
String url,
Properties sslProps)
Opens a HTTP connection to a remote server server certificate.
|
void |
putBaseHerf(boolean set)
Put the base href according the URL
|
int |
send()
Send HTTP request to the remote server.
|
void |
setCookie(String cookie)
Set the cookie
|
void |
setFollowRedirects(boolean set)
Set Follow Redirects
|
void |
setMethod(String method)
Set method
|
void |
setPassword(String password)
Set the password to use in the next request for basic authintication.
|
void |
setProxyServer(String proxyServer,
int port)
Set the proxy server and port to use if there is one.
|
void |
setReadTimeout(int readTimeOut) |
void |
setRequestProperties(Attribute[] reqProperties)
Sets the request properties.
|
void |
setRequestProperties(Attributes reqProperties)
Deprecated.
Please use setRequestProperties (Attribute[] reqProperties)
for maintaining parameters order in the URL.
|
void |
setRequestProperty(String headerName,
String headerValue)
Set the request header of a request, if the header already exists the value
given overrides the old value.
|
void |
setUsername(String user)
Set the username to use in the next request for basic authintication.
|
protected URL m_url
protected LinkedList<Attribute> reqPropertiesList
protected HttpURLConnection m_httpCon
HttpURLConnection which was made by the client.public void openConnection(String url) throws NullPointerException, IOException
url - the url to use in the HTTP requestNullPointerException - if an null argument was sentIOException - if the OpenConnection method failed.public void openConnection(String method, String url) throws NullPointerException, IOException
method - the method to use in the url request. (GET,POST,PUT etc)url - the url to use in the HTTP requestNullPointerException - if an null argument was sentIOException - if the OpenConnection method failed.public void openConnection(String method, String url, String username, String password, Properties sslProps) throws IOException
method - the method to use in the url request. (GET,POST,PUT etc)url - the url to use in the HTTP requestusername - username to use in the requestpassword - password to use in the requestNullPointerException - if an null argument was sentIOException - if the OpenConnection method failed.public void openConnectionServerCert(String method, String url, Properties sslProps) throws IOException
method - the method to use in the url request. (GET,POST,PUT etc)url - the url to use in the HTTP requestNullPointerException - if an null argument was sentIOException - if the OpenConnection method failed.public void disconnect()
public void setRequestProperty(String headerName, String headerValue) throws HttpClientException
headerName - header name to add to the HTTP request headersheaderValue - header value to use with the header.HttpClientExceptionpublic void appendRequestProperty(String name, String value) throws HttpClientException
name - name to add to the HTTP request property.value - value to use with the property.HttpClientExceptionpublic void setRequestProperties(Attributes reqProperties) throws HttpClientException
reqProperties - Attributes to be add as request properties.HttpClientExceptionpublic void setRequestProperties(Attribute[] reqProperties) throws HttpClientException
reqProperties - A set of Attribute objects to add as request properties.
These Attribute objects are reffered as a pair of String 'key' and a String
'value' pairs.HttpClientExceptionpublic int send()
throws IOException,
HttpClientException
openConnection(java.lang.String) method was called.
Use only after the connection is opened.
Returns the status code of the HTTP connection response.IOExceptionHttpClientExceptionpublic int getStatusCode()
throws IOException,
HttpClientException
send() method was called , use this method to get the HTTP status code
returned by the remote HTTP server.
to use after the request was sentIOExceptionHttpClientExceptionpublic String getStatusMessage() throws IOException, HttpClientException
send() method was called , use this method to get the HTTP status message
returned by the remote HTTP server.
to use after the request was sentIOExceptionHttpClientExceptionpublic String getResponseHeader(String headerName) throws IOException, HttpClientException
send() method was called , use this method to get the HTTP header value
by specifying the header name returned by the remote HTTP server.
to use after the request was sentheaderName - header name that we wish to get the value fromIOExceptionHttpClientExceptionpublic String getResponseHeader(int pos) throws IOException, HttpClientException
send() method was called , use this method to get the HTTP header value
by specifying the header position.
to use after the request was sentpos - header position in the list of headers that were returned by the remote serverIOExceptionHttpClientExceptionpublic String getHeaderFieldKey(int pos) throws IOException, HttpClientException
send() method was called , use this method to get the HTTP header name
by specifying the header position.
to use after the request was sentpos - header position in the list of headers that were returned by the remote serverIOExceptionHttpClientExceptionpublic String getResponseBody() throws IOException
send() method was called , use this method to get the HTTP response
body text that was returned by the HTTP remote server.
to use after the request was sentIOExceptionpublic InputStream getResponseInputStream() throws IOException, HttpClientException
InputStream.
to use after the request was sentIOExceptionHttpClientExceptionpublic void setUsername(String user)
user - username to set.public void setPassword(String password)
password - username to set.public void setProxyServer(String proxyServer, int port) throws NullPointerException, IndexOutOfBoundsException
proxyServer - - the name or IP address of the proxy server to useport - - the port to connect to the proxy server.NullPointerException - thrown if a null reference is sentIndexOutOfBoundsExceptionpublic List<String> getResponseHeaders() throws HttpClientException
HttpClientExceptionpublic URL getCurrentURL() throws HttpClientException
HttpClientExceptionpublic String getCookie()
public void setCookie(String cookie)
cookie - public void setFollowRedirects(boolean set)
set - public void putBaseHerf(boolean set)
set - public void addPostData(String postData)
postData - public void setMethod(String method)
method - GET or POSTpublic int getReadTimeout()
public void setReadTimeout(int readTimeOut)
readTimeOut - the read timeout to set| Access Rights |
|---|
| SC | DC | Public Part | ACH |
|---|---|---|---|
[sap.com] EP-RUNTIME
|
[sap.com] tc/ep/connectivity/services/api
|
api
|
EP-PIN
|
Copyright 2021 SAP SE Complete Copyright Notice