Package com.netlang.net
Class NHttpClient
java.lang.Object
com.netlang.net.NHttpClient
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
NRestClient
Class for communicating over HTTP.
This interface represents only the most basic contract for HTTP request
execution. It imposes no restrictions or particular details on the request
execution process and leaves the specifics of state management,
authentication and redirect handling up to individual implementations.
NHttpClient httpClient1 = new NHttpClient(0);
NHttpResponse response1=httpClient1.post("https://postman-echo.com/post","some text that is sent from netlang to postman and returned.","application/json");
int status=response1.getStatusCode();
if(status == 200){
String var1=response1.getContent("UTF-8");
Log.info(var1,null);
}else{
String var1=response1.getContent(null);
Log.info(var1,null);
}
httpClient1.close();
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionInitializes a newly createdHTTPClientNHttpClient(long timeout) Creates a new instanceNHttpClient(long timeout, Map<String, String> headers) Creates a new instanceNHttpClient(long timeout, Map<String, String> headers, int authType) Creates a new instanceNHttpClient(long timeout, Map<String, String> headers, String authKey, int authType) Creates a new instance -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDefaultHeader(String key, String value) voidclose()CloseGetdelete(org.apache.http.client.methods.HttpDelete request) Getget(org.apache.http.client.methods.HttpGet request) static voidpost(String url, List<NParameter> files) post(org.apache.http.client.methods.HttpPost request) PostpostFile(String url, NetlangFile file) postFile(String url, com.netlang.session.NetlangSession session, NetlangFile file) put(String url, List<NParameter> files) putFile(String url, NetlangFile file) putFile(String url, com.netlang.session.NetlangSession session, NetlangFile file) voidsetBaseUrl(String url) Set the base url of this client.
-
Field Details
-
TYPE_API_KEY
public static final int TYPE_API_KEY- See Also:
-
TYPE_TOKEN
public static final int TYPE_TOKEN- See Also:
-
-
Constructor Details
-
NHttpClient
public NHttpClient()Initializes a newly createdHTTPClient -
NHttpClient
public NHttpClient(long timeout) Creates a new instance- Parameters:
timeout-
-
NHttpClient
Creates a new instance -
NHttpClient
Creates a new instance- Parameters:
timeout-headers-authType-
-
NHttpClient
Creates a new instance- Parameters:
timeout-headers-authKey-authType-
-
-
Method Details
-
main
- Throws:
Exception
-
setBaseUrl
Set the base url of this client.- Parameters:
url-
-
close
public void close()Close- Specified by:
closein interfaceAutoCloseable
-
delete
public NHttpResponse delete(String url, Map<String, String> headers) throws IOException, InterruptedException- Parameters:
url-headers-- Returns:
- Throws:
IOExceptionInterruptedException
-
delete
public NHttpResponse delete(org.apache.http.client.methods.HttpDelete request) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
delete
Get- Parameters:
url-- Returns:
- Throws:
IOExceptionInterruptedException
-
get
public NHttpResponse get(String url, Map<String, String> headers) throws IOException, InterruptedException- Parameters:
url-headers-- Returns:
- Throws:
IOExceptionInterruptedException
-
get
Get- Parameters:
url-- Returns:
- Throws:
IOExceptionInterruptedException
-
get
public NHttpResponse get(org.apache.http.client.methods.HttpGet request) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
putFile
public NHttpResponse putFile(String url, String resourceid, String path) throws com.net4z.APIException - Throws:
com.net4z.APIException
-
putFile
- Throws:
com.net4z.APIException
-
putFile
- Throws:
com.net4z.APIException
-
putFile
public NHttpResponse putFile(String url, com.netlang.session.NetlangSession session, NetlangFile file) throws com.net4z.APIException - Throws:
com.net4z.APIException
-
putFile
public NHttpResponse putFile(String url, com.netlang.session.NetlangSession session, String resourceid, String path) throws com.net4z.APIException - Throws:
com.net4z.APIException
-
postFile
public NHttpResponse postFile(String url, String resourceid, String path) throws com.net4z.APIException - Throws:
com.net4z.APIException
-
postFile
- Throws:
com.net4z.APIException
-
postFile
- Throws:
com.net4z.APIException
-
postFile
public NHttpResponse postFile(String url, com.netlang.session.NetlangSession session, NetlangFile file) throws com.net4z.APIException - Throws:
com.net4z.APIException
-
postFile
public NHttpResponse postFile(String url, com.netlang.session.NetlangSession session, String resourceid, String path) throws com.net4z.APIException - Throws:
com.net4z.APIException
-
postFile
- Throws:
Exception
-
putFile
- Throws:
Exception
-
post
- Throws:
Exception
-
put
- Throws:
Exception
-
post
public NHttpResponse post(String url, File file, String contentType) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
post
public NHttpResponse post(String url, byte[] body, String contentType) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
put
public NHttpResponse put(String url, byte[] body, String contentType) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
get
public NHttpResponse get(String url, String body, String contentType) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
post
public NHttpResponse post(String url, String body, String contentType) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
patch
public NHttpResponse patch(String url, String body, String contentType) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
patch
public NHttpResponse patch(String url, byte[] body, String contentType) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
post
public NHttpResponse post(org.apache.http.client.methods.HttpPost request) throws IOException, InterruptedException Post- Parameters:
request-- Returns:
- Throws:
IOExceptionInterruptedException
-
addDefaultHeader
-