clienthttp

        import net.sf.json.JSONObject;
        import org.apache.http.HttpResponse;
        import org.apache.http.client.HttpClient;
        import org.apache.http.client.methods.HttpPost;
        import org.apache.http.entity.StringEntity;
        import org.apache.http.impl.client.DefaultHttpClient;
        import org.apache.http.protocol.HTTP;

        String url = "http://127.0.0.1:8080/Test/mytest.do";
        JSONObject jsonObj = new JSONObject();
        jsonObj.put("aaa", "aaa");
        jsonObj.put("bbb", "bbb");
        try {
            HttpPost httpPost = new HttpPost(url);
            StringEntity entity = new StringEntity(jsonObj.toString(), HTTP.UTF_8);
            entity.setContentType("application/json");
            httpPost.setEntity(entity);
            HttpClient client = new DefaultHttpClient();
            HttpResponse response = client.execute(httpPost);
        } catch (Exception e) {
            e.printStackTrace();
        }
本站公眾號
   歡迎關注本站公眾號,獲取更多信息