Skip to content

Commit

Permalink
Merge pull request #32 from bgarciaentornos/encodingFix
Browse files Browse the repository at this point in the history
Fix 500 error when sending utf8 text to Canvas

When trying to send non ISO-8859-1 text to Canvas it would return a 500 error in response to the request. This was because the default when unspecified was to use ISO-8859-1. This only affects some API calls to Canvas because some use JSON serialisation instead of form submission.
  • Loading branch information
buckett authored Apr 19, 2021
2 parents e6931da + ba69dc8 commit 37992ac
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main/java/edu/ksu/canvas/net/SimpleRestClient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.ksu.canvas.net;

import com.google.gson.Gson;
import edu.ksu.canvas.constants.CanvasConstants;
import edu.ksu.canvas.errors.ErrorHandler;
import edu.ksu.canvas.errors.GenericErrorHandler;
import edu.ksu.canvas.errors.UserErrorHandler;
Expand Down Expand Up @@ -163,7 +164,7 @@ public Response sendApiPost(OauthToken token, String url, Map<String, List<Strin
httpPost.setHeader("Authorization", "Bearer" + " " + token.getAccessToken());
List<NameValuePair> params = convertParameters(postParameters);

httpPost.setEntity(new UrlEncodedFormEntity(params));
httpPost.setEntity(new UrlEncodedFormEntity(params, CanvasConstants.URLENCODING_TYPE));
HttpResponse httpResponse = httpClient.execute(httpPost);
String content = handleResponse(httpResponse, httpPost);

Expand Down Expand Up @@ -219,7 +220,7 @@ public Response sendApiPut(OauthToken token, String url, Map<String, List<String
httpPut.setHeader("Authorization", "Bearer" + " " + token.getAccessToken());
List<NameValuePair> params = convertParameters(putParameters);

httpPut.setEntity(new UrlEncodedFormEntity(params));
httpPut.setEntity(new UrlEncodedFormEntity(params, CanvasConstants.URLENCODING_TYPE));
HttpResponse httpResponse = httpClient.execute(httpPut);
String content = handleResponse(httpResponse, httpPut);

Expand Down Expand Up @@ -254,7 +255,7 @@ public String getMethod() {
httpDelete.setHeader("Authorization", "Bearer" + " " + token.getAccessToken());
List<NameValuePair> params = convertParameters(deleteParameters);

httpDelete.setEntity(new UrlEncodedFormEntity(params));
httpDelete.setEntity(new UrlEncodedFormEntity(params, CanvasConstants.URLENCODING_TYPE));
HttpResponse httpResponse = httpClient.execute(httpDelete);

String content = handleResponse(httpResponse, httpDelete);
Expand Down

0 comments on commit 37992ac

Please sign in to comment.