fix(dolphinscheduler-alert): fix create http request error (#14793)

request type should use equalsIgnoreCase to equal,msg should add URLEncoder.encode

Co-authored-by: hunter-cloud09 <liuhunter09@gmail.com>
Co-authored-by: Aaron Wang <wangweirao16@gmail.com>
Co-authored-by: JinYong Li <42576980+JinyLeeChina@users.noreply.github.com>
This commit is contained in:
Hunter 2023-09-09 16:39:27 +08:00 committed by GitHub
parent 3fa69d2db8
commit 3c71fb05f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -32,10 +32,12 @@ import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
@ -111,12 +113,12 @@ public final class HttpSender {
}
private void createHttpRequest(String msg) throws MalformedURLException, URISyntaxException {
if (REQUEST_TYPE_POST.equals(requestType)) {
if (REQUEST_TYPE_POST.equalsIgnoreCase(requestType)) {
httpRequest = new HttpPost(url);
setHeader();
// POST request add param in request body
setMsgInRequestBody(msg);
} else if (REQUEST_TYPE_GET.equals(requestType)) {
} else if (REQUEST_TYPE_GET.equalsIgnoreCase(requestType)) {
// GET request add param in url
setMsgInUrl(msg);
URL unencodeUrl = new URL(url);
@ -139,7 +141,11 @@ public final class HttpSender {
if (!url.contains(URL_SPLICE_CHAR)) {
type = URL_SPLICE_CHAR;
}
url = String.format("%s%s%s=%s", url, type, contentField, msg);
try {
url = String.format("%s%s%s=%s", url, type, contentField, URLEncoder.encode(msg, DEFAULT_CHARSET));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
}