package common;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.swing.text.StringContent;
import java.io.File;
import java.nio.charset.Charset;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.util.EntityUtils;
import com.opensymphony.webwork.dispatcher.json.JSONArray;
import ewebeditor.admin.main_jsp;
import net.sf.json.JSONObject;
public class HttpClient {
public static void sendPost(String url,Map<String,String> map){
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,HttpVersion.HTTP_1_1);
httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "GBK");
try {
HttpPost post = new HttpPost(url);
// 提交文件类型的参数
MultipartEntity entity = new MultipartEntity();
for(Entry<String, String> s:map.entrySet()){
entity.addPart(s.getKey(),new StringBody(s.getValue(),Charset.forName("gbk")));
}
post.setEntity(entity);
HttpResponse response = httpClient.execute(post);
HttpEntity resEntity = response.getEntity();
String result = EntityUtils.toString(resEntity);
System.out.println("result:" + result);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Map map=new HashMap();
map.put("ID", "1408528201809170050");
map.put("Result", "1");
map.put("Opinion", "通过");
map.put("LicenceCode","");
map.put("LicenceName", "");
map.put("SystemCode", "5046D70C22DD47BA8129E9E59BC615E8");
map.put("LicenceName", "");
map.put("DeliverUser", "XXX");
map.put("DeliverTime", "2018-09-17 17:09:00");
JSONArray array=new JSONArray();
Map map1=new HashMap();
map1.put("DATA", array);
//map.put("fileJson",map1.T);
sendPost("http://59.195.128.222:88/accept/service/SubmitResult", map);
}
}