解决新增乱码问题

master
whb 8 months ago
parent 7158afe22f
commit b0567ebbb7

@ -17,6 +17,7 @@ import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
@ -317,8 +318,6 @@ public class StuJupyterController {
} }
try (CloseableHttpClient client = HttpClients.createDefault()) { try (CloseableHttpClient client = HttpClients.createDefault()) {
String notebookContent = "{" String notebookContent = "{"
+ "\"cells\": [" + "\"cells\": ["
@ -354,19 +353,12 @@ public class StuJupyterController {
+ "}"; + "}";
// 在根目录下创建新的笔记本 // 在根目录下创建新的笔记本
HttpPut createNotebookRequest = new HttpPut(JUPYTER_URL + "/api/contents/"+name+".ipynb"); HttpPut createNotebookRequest = new HttpPut(JUPYTER_URL + "/api/contents/"+name+".ipynb");
createNotebookRequest.addHeader("Authorization", "token " + adminJupyterTokenList.get(0).getToken()); createNotebookRequest.addHeader("Authorization", "token " + adminJupyterTokenList.get(0).getToken());
createNotebookRequest.addHeader("Content-Type", "application/json"); createNotebookRequest.addHeader("Content-Type", "application/json charset=UTF-8");
createNotebookRequest.setEntity(new StringEntity("{\"type\": \"notebook\", \"content\": " + notebookContent + "}")); //createNotebookRequest.setEntity(new StringEntity("{\"type\": \"notebook\", \"content\": " + notebookContent + "}"));
createNotebookRequest.setEntity(new StringEntity("{\"type\": \"notebook\", \"content\": " + notebookContent + "}", ContentType.APPLICATION_JSON.withCharset("UTF-8")));
try (CloseableHttpResponse createNotebookResponse = client.execute(createNotebookRequest)) { try (CloseableHttpResponse createNotebookResponse = client.execute(createNotebookRequest)) {
int statusCode = createNotebookResponse.getStatusLine().getStatusCode(); int statusCode = createNotebookResponse.getStatusLine().getStatusCode();
if (statusCode == 201) { if (statusCode == 201) {

Loading…
Cancel
Save