Skip to content

Commit d2bc761

Browse files
Add deleted part
1 parent 194bc7b commit d2bc761

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

java/src/main/java/com/genexus/internet/HttpClientJavaLib.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -508,29 +508,39 @@ public void execute(String method, String url) {
508508
}
509509
response = httpClient.execute(httpget, httpClientContext);
510510
}
511-
512511
} else if (method.equalsIgnoreCase("POST")) {
513512
HttpPost httpPost = new HttpPost(url.trim());
514513
httpPost.setConfig(reqConfig);
515514
Set<String> keys = getheadersToSend().keySet();
516-
boolean hasConentType = false;
515+
boolean hasContentType = false;
517516
for (String header : keys) {
518517
httpPost.addHeader(header, getheadersToSend().get(header));
519518
if (header.equalsIgnoreCase("Content-type"))
520-
hasConentType = true;
519+
hasContentType = true;
521520
}
522-
if (!hasConentType) // Si no se setea Content-type, se pone uno default
523-
httpPost.addHeader("Content-type", "application/x-www-form-urlencoded");
524-
525-
ByteArrayEntity dataToSend;
526-
if (!getIsMultipart() && getVariablesToSend().size() > 0)
527-
dataToSend = new ByteArrayEntity(CommonUtil.hashtable2query(getVariablesToSend()).getBytes());
528-
else
529-
dataToSend = new ByteArrayEntity(getData());
530-
httpPost.setEntity(dataToSend);
531-
521+
HttpEntity entity;
522+
if (getIsMultipart()) {
523+
httpPost.removeHeaders("Content-type");
524+
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
525+
if (getVariablesToSend() != null && getVariablesToSend().size() > 0) {
526+
for (Object obj : getVariablesToSend().entrySet()) {
527+
Map.Entry entry = (Map.Entry) obj;
528+
builder.addTextBody(entry.getKey().toString(), entry.getValue().toString(), ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8));
529+
}
530+
} else if (getData() != null && getData().length > 0) {
531+
builder.addBinaryBody("file", getData(), ContentType.DEFAULT_BINARY, "file");
532+
}
533+
entity = builder.build();
534+
} else {
535+
if (!hasContentType)
536+
httpPost.addHeader("Content-type", "application/x-www-form-urlencoded");
537+
if (getVariablesToSend() != null && getVariablesToSend().size() > 0)
538+
entity = new ByteArrayEntity(CommonUtil.hashtable2query(getVariablesToSend()).getBytes());
539+
else
540+
entity = new ByteArrayEntity(getData());
541+
}
542+
httpPost.setEntity(entity);
532543
response = httpClient.execute(httpPost, httpClientContext);
533-
534544
} else if (method.equalsIgnoreCase("PUT")) {
535545
HttpPut httpPut = new HttpPut(url.trim());
536546
httpPut.setConfig(reqConfig);

0 commit comments

Comments
 (0)