Browse Source

add httpkit upload response

pull/14/head
onlyxx 8 months ago
parent
commit
4dad758a17
  1. 4
      src/main/java/com/fanruan/api/design/work/ConnectionComboBoxPanel.java
  2. 23
      src/main/java/com/fanruan/api/net/http/HttpKit.java

4
src/main/java/com/fanruan/api/design/work/ConnectionComboBoxPanel.java

@ -130,7 +130,11 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel {
ConfigurationKit.modify(ConnectionConfig.class, new Runner() { ConfigurationKit.modify(ConnectionConfig.class, new Runner() {
@Override @Override
public void run() { public void run() {
try {
connectionListPane.update(connectionConfig); connectionListPane.update(connectionConfig);
} catch (Exception e) {
throw new RuntimeException(e);
}
} }
}, new WorkerCallBack() { }, new WorkerCallBack() {
@Override @Override

23
src/main/java/com/fanruan/api/net/http/HttpKit.java

@ -44,6 +44,7 @@ import java.net.URISyntaxException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import static com.fanruan.api.net.http.rs.HttpRequestType.POST; import static com.fanruan.api.net.http.rs.HttpRequestType.POST;
@ -193,12 +194,12 @@ public class HttpKit {
/** /**
* 发起POST JSON请求并获取返回的文本 * 发起POST JSON请求并获取返回的文本
* * 以前版本只支持jsonObject 修改为object就可以支持多种json格式
* @param url 响应请求的的服务器地址 * @param url 响应请求的的服务器地址
* @param params POST请求的参数 * @param params POST请求的参数
* @return 服务器返回的文本内容 * @return 服务器返回的文本内容
*/ */
public static String postJSON(String url, JSONObject params, Map<String, String> headers) throws IOException { public static String postJSON(String url, Object params, Map<String, String> headers) throws IOException {
StringEntity jsonEntity = new StringEntity(params.toString(), "UTF-8"); StringEntity jsonEntity = new StringEntity(params.toString(), "UTF-8");
jsonEntity.setContentEncoding("UTF-8"); jsonEntity.setContentEncoding("UTF-8");
if (headers != null) { if (headers != null) {
@ -484,8 +485,8 @@ public class HttpKit {
* @param file 要上传的文件默认的文件编码为utf-8 * @param file 要上传的文件默认的文件编码为utf-8
* @throws IOException 上传中出现错误则抛出此异常 * @throws IOException 上传中出现错误则抛出此异常
*/ */
public static void upload(String url, File file) throws IOException { public static String upload(String url, File file) throws IOException {
upload(url, file, Charset.forName("utf-8")); return upload(url, file, StandardCharsets.UTF_8);
} }
/** /**
@ -496,8 +497,8 @@ public class HttpKit {
* @param charset 文件的编码 * @param charset 文件的编码
* @throws IOException 上传中出现错误则抛出此异常 * @throws IOException 上传中出现错误则抛出此异常
*/ */
public static void upload(String url, File file, Charset charset) throws IOException { public static String upload(String url, File file, Charset charset) throws IOException {
upload(url, new FileEntity(file), charset); return upload(url, new FileEntity(file), charset);
} }
/** /**
@ -520,8 +521,8 @@ public class HttpKit {
* @param charset 文件的编码 * @param charset 文件的编码
* @throws IOException 上传中出现错误则抛出此异常 * @throws IOException 上传中出现错误则抛出此异常
*/ */
public static void upload(String url, FileEntity fileEntity, Charset charset) throws IOException { public static String upload(String url, FileEntity fileEntity, Charset charset) throws IOException {
upload(url, fileEntity, charset, Collections.<String, String>emptyMap(), POST); return upload(url, fileEntity, charset, Collections.<String, String>emptyMap(), POST);
} }
/** /**
@ -551,8 +552,8 @@ public class HttpKit {
* @param httpRequestType 请求类型 * @param httpRequestType 请求类型
* @throws IOException 上传中出现错误则抛出此异常 * @throws IOException 上传中出现错误则抛出此异常
*/ */
public static void upload(String url, HttpEntity reqEntity, Charset charset, Map<String, String> headers, HttpRequestType httpRequestType) throws IOException { public static String upload(String url, HttpEntity reqEntity, Charset charset, Map<String, String> headers, HttpRequestType httpRequestType) throws IOException {
executeAndParse(HttpRequest return executeAndParse(HttpRequest
.custom() .custom()
.url(url) .url(url)
.headers(headers) .headers(headers)
@ -560,7 +561,7 @@ public class HttpKit {
.httpEntity(reqEntity) .httpEntity(reqEntity)
.encoding(charset.toString()) .encoding(charset.toString())
.build(), .build(),
UploadResponseHandle.DEFAULT); new TextResponseHandle(charset.toString()));
} }
/** /**

Loading…
Cancel
Save