Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Websocat | 5,914 | 16 days ago | 21 | September 24, 2022 | 111 | mit | Rust | |||
Command-line client for WebSockets, like netcat (or curl) for ws:// with advanced socat-like functions | ||||||||||
Php Curl Class | 3,184 | 690 | 352 | 10 days ago | 96 | July 10, 2023 | 2 | unlicense | PHP | |
PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs | ||||||||||
Faster Than Requests | 1,021 | 4 | 10 days ago | 18 | February 24, 2021 | mit | Nim | |||
Faster requests on Python 3 | ||||||||||
Pgsql Http | 1,001 | 2 months ago | 3 | mit | C | |||||
HTTP client for PostgreSQL, retrieve a web page from inside the database. | ||||||||||
Aws Es Proxy | 578 | 7 months ago | 5 | June 05, 2020 | 36 | apache-2.0 | Go | |||
aws-es-proxy is a small web server application sitting between your HTTP client (browser, curl, etc...) and Amazon Elasticsearch service. | ||||||||||
Go Httpclient | 454 | 16 | 22 | 3 months ago | 19 | September 30, 2022 | 5 | mit | Go | |
Advanced HTTP client for golang | ||||||||||
Php Whois | 343 | 4 | 5 | 8 months ago | 42 | June 14, 2022 | 18 | mit | PHP | |
PHP WHOIS provides parsed and raw whois lookup of domains and ASN routes. PHP 8.0 compatible (5.4+ old versions) | ||||||||||
Pipe To Me | 324 | 2 years ago | mit | Go | ||||||
Stream data over http using curl. | ||||||||||
Notica | 285 | a year ago | 6 | mit | JavaScript | |||||
Send browser notifications from your terminal. No installation. No registration. | ||||||||||
Pupflare | 227 | a month ago | 5 | JavaScript | ||||||
A webpage proxy that request through Chromium (puppeteer) - can be used to bypass Cloudflare anti bot / anti ddos on any application (like curl) |
java-curl is a pure-java HTTP utility implemented based on HttpURLConnection in the standard JRE, while the usage references to the commonly-used CURL command line tool under Linux.
CUrl.opt(...)
method. For a list of supported switches, please refer to the table.opt()
method accepts multiple parameters and values. Note that if a CUrl switch needing a value, then the switch and value should be passed-in as two method parameters, e.g.:
curl.opt("-d", "a=b", "-L")
CUrl.IO
is the abstracted interface for both input and output, its subclasses include:
CUrl.MemIO
: corresponds to a byte buffer for direct memory accessCUrl.FileIO
: corresponding to physical fileCUrl.WrappedIO
: Simple wrapper for either InputStream or OutputStreamcert(io, password)
: Read the client certificate from IOdata(io, binary)
: read POST data from IOform(name, io)
: Read file/text item from IO to submit an multi-part post for file-uploadingcookie(io)
: Read cookies from IOcookieJar(io)
: Save cookies to IOdumpHeader(io)
: dumps the response header to IOstdout/stderr
: redirect standard-output/standard-error to IOcurl("http://...").opt("-D", "-", "-c", "-")
CookieManager/CookieStore
, but there is a serious problem, the API design is not reasonable, CookieStore
can only have one globally singleton instance. That means in one VM, if multiple requests access the same site concurrently, then they always share the same cookies, this is not acceptable in many circumstances.ThreadLocal
-based CookieStore
, each thread has a separate cookie-store, which solves the above problem perfectly.--cookie/--cookie-jar
parameter, you can also use getCookieStore
to get the CookieStore
singleton, directly call its add/getCookies
and other methods to read and write the current thread's cookies.--cookie/--cookie-jar
parameter every time.cookie("")
call on the first request in the thread, which will clear the thread-local cookie-store.CUrl.Resolver
is used to directly deserialize the raw response byte array into custom Java object, such as Xml, Json, Html, etc., can be combined with DOM4J, Jackson/Gson, Jsoup and other third-party libraries.Resolver.resolve()
method, if CUrl.Recoverable
or its subclass instances are thrown, then this fail can be retried. If retry parameters are specified, CUrl will automatically retry the given number of times or given duration
Recoverable
to instruct CUrl to retry.cert(io, password)
or opt("-E", "path/to/file\:password")
.insecure()
or opt("-k")
to instruct CUrl to ignore certificate security checks.location()
or opt("-L")
to indicate that the redirect should be automatically followed.CUrl.getLocations().get(0)
to get the redirected location URL after getting the 30X response.data()
call demonstrations that --data
switch can be specified multiple times, and the parameter values can be overwritten. public void httpPost() {
CUrl curl = new CUrl("http://httpbin.org/post")
.data("hello=world&foo=bar")
.data("foo=overwrite");
curl.exec();
assertEquals(200, curl.getHttpCode());
}
public void insecureHttpsViaFiddler() {
CUrl curl = new CUrl("https://httpbin.org/get")
.proxy("127.0.0.1", 8888) // Use Fiddler to capture & parse HTTPS traffic
.insecure(); // Ignore certificate check since it's issued by Fiddler
curl.exec();
assertEquals(200, curl.getHttpCode());
}
public void uploadMultipleFiles() {
CUrl.MemIO inMemFile = new CUrl.MemIO();
try { inMemFile.getOutputStream().write("text file content blabla...".getBytes()); } catch (Exception ignored) {}
CUrl curl = new CUrl("http://httpbin.org/post")
.form("formItem", "value") // a plain form item
.form("file", inMemFile) // in-memory "file"
.form("image", new CUrl.FileIO("D:\\tmp\\a2.png")); // A file in storage
curl.exec();
assertEquals(200, curl.getHttpCode());
}
header()
, or multiple request headers at a time with headers()
. public void customUserAgentAndHeaders() {
String mobileUserAgent = "Mozilla/5.0 (Linux; U; Android 8.0.0; zh-cn; KNT-AL10 Build/HUAWEIKNT-AL10) "
+ "AppleWebKit/537.36 (KHTML, like Gecko) MQQBrowser/7.3 Chrome/37.0.0.0 Mobile Safari/537.36";
Map<String, String> fakeAjaxHeaders = new HashMap<String, String>();
fakeAjaxHeaders.put("X-Requested-With", "XMLHttpRequest");
fakeAjaxHeaders.put("Referer", "http://somesite.com/fake_referer");
CUrl curl = new CUrl("http://httpbin.org/get")
.opt("-A", mobileUserAgent) // simulate a mobile browser
.headers(fakeAjaxHeaders) // simulate an AJAX request
.header("X-Auth-Token: xxxxxxx"); // other custom header, this might be calculated elsewhere
curl.exec();
assertEquals(200, curl.getHttpCode());
}
public void threadSafeCookies() {
final CountDownLatch count = new CountDownLatch(3);
final CUrl[] curls = new CUrl[3];
for (int i = 3; --i >= 0;) {
final int idx = i;
new Thread() {
public void run() {
CUrl curl = curls[idx] = new CUrl("http://httpbin.org/get")
.cookie("thread" + idx + "=#" + idx);
curl.exec();
count.countDown();
}
}.start();
}
try { count.await(); } catch (Exception ignored) {} // make sure all requests are done
assertEquals(200, curls[0].getHttpCode());
assertEquals("thread0=#0", deepGet(curls[0].getStdout(jsonResolver, null), "headers.Cookie"));
assertEquals("thread1=#1", deepGet(curls[1].getStdout(jsonResolver, null), "headers.Cookie"));
assertEquals("thread2=#2", deepGet(curls[2].getStdout(jsonResolver, null), "headers.Cookie"));
}
private CUrl.Resolver<Document> htmlResolver = new CUrl.Resolver<Document>() {
@SuppressWarnings("unchecked")
@Override
public Document resolve(int httpCode, byte[] responseBody) throws Throwable {
String html = new String(responseBody, "UTF-8");
return Jsoup.parse(html);
}
};
public void customResolver() {
CUrl curl = new CUrl("http://httpbin.org/html");
Document html = curl.exec(htmlResolver, null);
assertEquals(200, curl.getHttpCode());
assertEquals("Herman Melville - Moby-Dick", html.select("h1:first-child").text());
}
java -jar java-curl-1.2.2.jar https://httpbin.org/get ^
-x 127.0.0.1:8888 -k ^
-A "Mozilla/5.0 (Linux; U; Android 8.0.0; zh-cn; KNT-AL10 Build/HUAWEIKNT-AL10) AppleWebKit/537.36 (KHTML, like Gecko) MQQBrowser/7.3 Chrome/37.0.0.0 Mobile Safari/537.36" ^
-H "Referer: http://somesite.com/fake_referer" ^
-H "X-Requested-With: XMLHttpRequest" ^
-H "X-Auth-Token: xxxxxxx"
# Convert website certificate and private key to p12/pfx certificate
openssl pkcs12 -export -in cert.pem -inkey key.pem -name cert -out cert.p12
# Convert p12/pfx to jks format and set the password to 123456
keytool -importkeystore -srckeystore cert.p12 -srcstoretype pkcs12 -srcstorepass 123456 -destkeystore cert.jks -deststorepass 123456
# Convert Jks format to bks format, BKS certificate is applicable to Android platform
keytool -importkeystore -srckeystore cert.jks -srcstoretype JKS -srcstorepass 123456 -destkeystore cert.bks -deststoretype BKS -deststorepass 123456 -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath "path/to/bcprov-jdk16-140.jar"
# Call java-curl on the command line, you must specify the password of the JKS file.
java -jar java-curl-1.2.2.jar https://mysecuritysite.com -E cert.jks:123456
Switch Name | Short-cut Method | Description |
---|---|---|
-E, --cert | cert | <certificate:password> Specify the client certificate file and password, only support JKS format certificate (only BKS is supported on Android) |
--compressed | NO | Request to gzip compressed response data (but need server side support) |
--connect-timeout | timeout | Connection timeout time, in seconds, default 0, that is, never timeout |
-b, --cookie | cookie | Read cookies from file / IO object / parameter string |
-c, --cookie-jar | cookieJar | Cookie output to file / IO object |
-d, --data, --data-ascii | data | Add post data, if used multiple times, use '&' to connect, the added form item key-value pair will overwrite the previous one. If data starts with '@', the latter part is used as the file name, and the data is used by File read in, and delete carriage return in the file |
--data-raw | NO | Same as "--data", but not special handling for '@' |
--data-binary | NO | Same as "--data", but does not delete carriage return line feed characters when reading in files |
--data-urlencode | data(data,charset) | Same as "--data", but with Url-Encode for data, you can append a character set after this option, such as "--data-urlencode-GBK". If the first character of the parameter value is '=': the following string is whole Url-Encode; If the parameter value contains '=': split the string into key-value pairs separated by '&', the key-value pairs are split with '=', for key-value pairs All values in the value are Url-Encode. If the parameter value does not contain '=': -- If the string does not contain '@', then the entire string is Url-Encode -- If the string contains '@' then split the string with '@', after '@' is the input file name, then read the text from the file and perform Url-Encode, the front part of '@' is the key -- If '@' is the first character, the text read in the file is generally Url-Encode |
-D, --dump-header | dumpHeader | Output the response header of the last step jump to the given file / IO object |
-F, --form | form | Initiate file upload, add a file or form item. - If the initial value of the parameter value is '@' or '<', the data is read from the specified file for uploading. The difference between '@' and '<' is that the file content of '@' is uploaded as a file attachment, and the file content of '<' is used as the value of the normal form item. - Otherwise, the parameter value is used as the value of the normal form item. |
--form-string | form(formString) | Initiate file upload, add 1 non-file form item, note that this method does not specialize for '@' |
-G, --get | NO | Force the GET method. Will add the key-value pair specified by -d to the url as the query parameter |
-H, --header | header | Add a request header line with the syntax: -- "Host: baidu.com": Add/set a normal request header key-value pair -- "Accept:": Delete the given request header -- "X-Custom-Header;": Add/set a custom request header with a value of null |
-I, --head | NO | Request using the HEAD method |
-k, --insecure | insecure | Ignore HTTPS certificate security check |
-v, --verbose | verbose | More verbose output with timestamp |
-L, --location | location | Automatic follow redirect (not enabled by default) |
-m, --max-time | timeout | Transmission timeout, in seconds, default 0, that is, never timeout |
-o, --output | output | Specify the output file / IO object, the default stdout, which is "-" |
-x, --proxy | proxy | Set proxy server |
-U, --proxy-user | NO | Set proxy server authorization |
-e, --referer | NO | Set the Referer request header content |
--retry | retry | Set the number of retries, default 0 |
--retry-delay | retry | Set the delay between two retries, in seconds, default 0 |
--retry-max-time | retry | Set the maximum retry total time, in seconds, default 0, that is, never time out |
-s, --silent | NO | Set silent mode, which suppress all outputs |
--stderr | stderr | Set stderr output file / IO object, default stdout |
-u, --user | NO | Set the HTTP Authorization information. Note that it is only used for simple HTTP authentication, which is the case where the system dialog box pops up in the browser. |
--url | CUrl, url | Set the request address, this CUrl library does not support multiple url requests. |
-A, --user-agent | NO | Set the "User-Agent" request header content |
-X, --request | NO | Specify HTTP request method |
--x-max-download | NO | Abandon download after the transfer reaches a given number of bytes (inaccurate) |
--x-tags | NO | Set additional key-value pairs to be stored in the current CUrl instance for passing additional parameters in programming |