Skip to content

Commit a2b8b75

Browse files
tomas-sexenianiroqueta
authored andcommitted
Handle boundaries in multipart request (#940)
* Remove extra line break * Handle boundaries in multipart request * Handle boundaries in multipart request --------- Co-authored-by: iroqueta <[email protected]> (cherry picked from commit a8d8b3f)
1 parent c99ea79 commit a2b8b75

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

common/src/main/java/com/genexus/internet/GXHttpClient.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -568,15 +568,22 @@ protected String setPathUrl(String url) {
568568
return url;
569569
}
570570

571+
boolean firstMultiPart;
571572
@SuppressWarnings("unchecked")
572573
protected byte[] getData()
573574
{
574575
byte[] out = new byte[0];
575576

577+
firstMultiPart = false;
578+
int variablesCount = getVariablesToSend().size();
579+
int count = 1;
576580
for (Object key: getVariablesToSend().keySet())
577581
{
582+
if (count == variablesCount)
583+
firstMultiPart = true;
578584
String value = getMultipartTemplate().getFormDataTemplate((String)key, (String)getVariablesToSend().get(key));
579585
getContentToSend().add(0, value); //Variables al principio
586+
count++;
580587
}
581588

582589
for (int idx = 0; idx < getContentToSend().size(); idx++)
@@ -792,7 +799,10 @@ String getHeaderTemplate(String name, String fileName, String mimeType){
792799
}
793800
String getFormDataTemplate(String varName, String value){
794801
String contentType = getContentTypeFromString(value);
795-
return "\r\n--" + boundary + "\r\nContent-Disposition: form-data; name=\"" + varName + "\"\r\n" + ((contentType != null)? "Content-Type: " + contentType + "\r\n" : "") + "\r\n" + value;
802+
String beginformDataTemplate = "\r\n--";
803+
if (firstMultiPart)
804+
beginformDataTemplate = "--";
805+
return beginformDataTemplate + boundary + "\r\nContent-Disposition: form-data; name=\"" + varName + "\"\r\n" + ((contentType != null)? "Content-Type: " + contentType + "\r\n" : "") + "\r\n" + value;
796806
}
797807

798808
private String getContentTypeFromString(String value){

0 commit comments

Comments
 (0)