package org.external.WeChatBill;
import java.io.IOException;
import net.sf.json.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class postjson {
public static String sendInfo(String sendurl, String data) {
//System.out.println("data:"+data);
CloseableHttpClient client = HttpClients.createDefault();
HttpPost post = new HttpPost(sendurl);
StringEntity myEntity = new StringEntity(data,
ContentType.APPLICATION_JSON);
post.setEntity(myEntity);
String responseContent = null;
CloseableHttpResponse response = null;
try {
response = client.execute(post);
if (response.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = response.getEntity();
responseContent = EntityUtils.toString(entity, "UTF-8");
String aa = null;
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (response != null)
response.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (client != null)
client.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return responseContent;
}
Java连接WebServce
最新推荐文章于 2022-08-30 17:14:44 发布