Include POST request
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
61c628c344
commit
e3014ece84
@ -46,10 +46,8 @@ public class client {
|
|||||||
postRes = new POSTRequest("https://postman-echo.com/post","Test body", 30000, "header1","value1", "header2","value2");
|
postRes = new POSTRequest("https://postman-echo.com/post","Test body", 30000, "header1","value1", "header2","value2");
|
||||||
System.out.println(((HttpResponse<String>)postRes.run()).body());*/
|
System.out.println(((HttpResponse<String>)postRes.run()).body());*/
|
||||||
|
|
||||||
POSTRequest postRes = new POSTRequest("https://postman-echo.com/post",Path.of(".gitignore"));
|
POSTRequest postRes = new POSTRequest("https://postman-echo.com/post",Path.of("..",".gitignore"));
|
||||||
System.out.println(((HttpResponse<String>)postRes.run()).body());
|
System.out.println(((HttpResponse<String>)postRes.run()).body());
|
||||||
|
|
||||||
|
|
||||||
} catch (FailedResponseException e) {
|
} catch (FailedResponseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package sig.requests;
|
package sig.requests;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.http.HttpHeaders;
|
import java.net.http.HttpHeaders;
|
||||||
import java.net.http.HttpRequest;
|
import java.net.http.HttpRequest;
|
||||||
@ -8,10 +10,12 @@ import java.net.http.HttpResponse;
|
|||||||
import java.net.http.HttpClient.Builder;
|
import java.net.http.HttpClient.Builder;
|
||||||
import java.net.http.HttpClient.Version;
|
import java.net.http.HttpClient.Version;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import javax.net.ssl.SSLSession;
|
import javax.net.ssl.SSLSession;
|
||||||
|
|
||||||
|
import sig.MultipartUtility;
|
||||||
import sig.exceptions.FailedResponseException;
|
import sig.exceptions.FailedResponseException;
|
||||||
|
|
||||||
public class POSTRequest extends GETRequest{
|
public class POSTRequest extends GETRequest{
|
||||||
@ -46,40 +50,60 @@ public class POSTRequest extends GETRequest{
|
|||||||
@Override
|
@Override
|
||||||
public HttpResponse<?> run() throws FailedResponseException {
|
public HttpResponse<?> run() throws FailedResponseException {
|
||||||
if (uploadFile!=null) {
|
if (uploadFile!=null) {
|
||||||
return new HttpResponse<String>(){
|
String charset = "UTF-8";
|
||||||
@Override
|
File file = uploadFile.toFile();
|
||||||
public int statusCode() {
|
String requestURL = url;
|
||||||
return 0;
|
|
||||||
}
|
try {
|
||||||
@Override
|
MultipartUtility multipart = new MultipartUtility(requestURL, charset);
|
||||||
public HttpRequest request() {
|
|
||||||
return null;
|
multipart.addHeaderField("User-Agent", "SIG HTTPCLIENT");
|
||||||
}
|
|
||||||
@Override
|
multipart.addFilePart("fileUpload", file);
|
||||||
public Optional<HttpResponse<String>> previousResponse() {
|
|
||||||
return null;
|
List<String> response = multipart.finish();
|
||||||
}
|
return new HttpResponse<String>(){
|
||||||
@Override
|
@Override
|
||||||
public HttpHeaders headers() {
|
public int statusCode() {
|
||||||
return null;
|
return 0;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String body() {
|
public HttpRequest request() {
|
||||||
return "Response";
|
return null;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public Optional<SSLSession> sslSession() {
|
public Optional<HttpResponse<String>> previousResponse() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public URI uri() {
|
public HttpHeaders headers() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public Version version() {
|
public String body() {
|
||||||
return null;
|
StringBuilder sb = new StringBuilder();
|
||||||
}
|
for (String s : response) {
|
||||||
};
|
sb.append(s);
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Optional<SSLSession> sslSession() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public URI uri() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Version version() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} catch (IOException ex) {
|
||||||
|
System.err.println(ex);
|
||||||
|
throw new FailedResponseException("Could not send response for POST File upload. THIS SHOULD NOT BE HAPPENING!");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return super.run();
|
return super.run();
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ function check() {
|
|||||||
if [ "$g" != "md5" ]; then
|
if [ "$g" != "md5" ]; then
|
||||||
if [ -f $1$g ];
|
if [ -f $1$g ];
|
||||||
then
|
then
|
||||||
|
if [ "$g" != ".coauthors" ]; then
|
||||||
echo "++Redownload $1$g..."
|
echo "++Redownload $1$g..."
|
||||||
if [ -f "$1$g" ]; then
|
if [ -f "$1$g" ]; then
|
||||||
#Read the 2nd line and see if it has a special directory.
|
#Read the 2nd line and see if it has a special directory.
|
||||||
@ -58,6 +59,7 @@ function check() {
|
|||||||
echo "===Could not find directory, assuming regular scripts directory exists."
|
echo "===Could not find directory, assuming regular scripts directory exists."
|
||||||
curl -H 'Cache-Control: no-cache, no-store' https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1$g --output scripts/$g
|
curl -H 'Cache-Control: no-cache, no-store' https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1$g --output scripts/$g
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "++==Downloading $1$g..."
|
echo "++==Downloading $1$g..."
|
||||||
curl -H 'Cache-Control: no-cache, no-store' https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1$g --output $1$g
|
curl -H 'Cache-Control: no-cache, no-store' https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1$g --output $1$g
|
||||||
|
Loading…
x
Reference in New Issue
Block a user