body请求支持更多中类型

This commit is contained in:
panjing
2017-03-14 17:16:44 +08:00
parent 1001966262
commit cb45fe9548
9 changed files with 25 additions and 20 deletions
+6 -4
View File
@@ -2,14 +2,16 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wezoz.nat</groupId>
<artifactId>wezoz-nat-client</artifactId>
<groupId>com.wenat</groupId>
<artifactId>wenat-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>wezoz-nat-client</name>
<name>wenat-client</name>
<url>https://www.wezoz.com</url>
<description>
wenat.cn 这个域名没备案,.com的域名将就用吧~
</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
@@ -1,4 +1,4 @@
package com.wezoz.nat;
package cn.wenat;
public interface CallListener {
@@ -1,4 +1,4 @@
package com.wezoz.nat;
package cn.wenat;
import java.sql.Time;
import java.util.HashMap;
@@ -14,9 +14,9 @@ import org.json.JSONException;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.wezoz.nat.form.MainForm;
import com.wezoz.nat.utils.HttpClientUtils;
import cn.wenat.form.MainForm;
import cn.wenat.utils.HttpClientUtils;
import io.socket.client.IO;
import io.socket.client.IO.Options;
import io.socket.client.Socket;
@@ -239,7 +239,7 @@ public class LocalServer {
response = HttpClientUtils.post(post, params);
}else {
//其他的全部postBody
response = HttpClientUtils.postBody(post, request.getString("params"), encoding);
response = HttpClientUtils.postBody(post, request.getString("body"), encoding);
}
} catch (Exception e) {
response = new Response();
@@ -1,4 +1,4 @@
package com.wezoz.nat;
package cn.wenat;
import java.io.Serializable;
import java.util.Map;
@@ -1,4 +1,4 @@
package com.wezoz.nat;
package cn.wenat;
import io.socket.emitter.Emitter.Listener;
@@ -1,4 +1,4 @@
package com.wezoz.nat.form;
package cn.wenat.form;
import java.awt.Color;
import java.awt.event.WindowAdapter;
@@ -1,4 +1,4 @@
package com.wezoz.nat.form;
package cn.wenat.form;
import java.awt.Color;
import java.awt.event.ActionEvent;
@@ -18,8 +18,8 @@ import javax.swing.JTextField;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import com.wezoz.nat.CallListener;
import com.wezoz.nat.LocalServer;
import cn.wenat.CallListener;
import cn.wenat.LocalServer;
public class MainForm extends BaseForm {
@@ -73,7 +73,7 @@ public class MainForm extends BaseForm {
try {
String host = txtHost.getText();
server = new LocalServer();
server.setServer("http://wezoz.com:3001");
server.setServer("http://127.0.0.1:3001");
server.setForward(host);
server.setDomain(txtDomain.getText());
server.setCallListener(new CallListener() {
@@ -1,4 +1,4 @@
package com.wezoz.nat.utils;
package cn.wenat.utils;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
@@ -48,7 +48,8 @@ import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import com.alibaba.fastjson.JSON;
import com.wezoz.nat.Response;
import cn.wenat.Response;
/**
* http请求工具 httpclient4.5
@@ -205,7 +206,9 @@ public class HttpClientUtils {
public static Response postBody(HttpPost httpPost, String body,String encoding) {
Response res = null;
try {
httpPost.setEntity(new StringEntity(body, encoding));
StringEntity entity=new StringEntity(body,encoding);
// entity.setContentType(httpPost.getFirstHeader("content-type"));
httpPost.setEntity(entity);
CloseableHttpResponse response = getClient().execute(httpPost);
res = getContent(response);
} catch (Exception e) {
@@ -1,4 +1,4 @@
package com.wezoz.nat.utils;
package cn.wenat.utils;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;