java如何获取webService最底层的传输java数据传输加密

&&完java如何通过http post请求传递json参数到restful webservice服务接口获取数据?java后台要使用http restful调用webservice接口获取数据,代码要怎么写啊?15个牛币所有回答列表(2)import commons.weibo4j.util.URLEncodeUimport org.apache.http.HttpRimport org.apache.http.HttpSimport org.apache.http.HttpVimport org.apache.http.NameValuePimport org.apache.http.client.ClientProtocolEimport org.apache.http.client.HttpCimport org.apache.http.client.entity.UrlEncodedFormEimport org.apache.http.client.methods.HttpGimport org.apache.http.client.methods.HttpPimport org.apache.http.conn.ClientConnectionMimport org.apache.http.conn.params.ConnManagerPimport org.apache.http.conn.scheme.PlainSocketFimport org.apache.http.conn.scheme.Simport org.apache.http.conn.scheme.SchemeRimport org.apache.http.conn.ssl.SSLSocketFimport org.apache.http.conn.ssl.X509HostnameVimport org.apache.http.entity.StringEimport org.apache.http.impl.client.DefaultHttpCimport org.apache.http.impl.conn.tsccm.ThreadSafeClientConnMimport org.apache.http.params.BasicHttpPimport org.apache.http.params.HttpConnectionPimport org.apache.http.params.HttpPimport org.apache.http.params.HttpProtocolPimport org.apache.http.protocol.HTTP;import org.apache.http.util.EntityUimport javax.net.ssl.*;import java.io.IOEimport java.io.UnsupportedEncodingEimport java.net.URLDimport java.net.URLEimport java.security.KeyManagementEimport java.security.NoSuchAlgorithmEimport java.security.cert.CertificateEimport java.security.cert.X509Cimport java.util.HashMimport java.util.Limport java.util.Mimport java.util.Map.E/**&* 网络请求工具&*&* @author Haner&*/public class HttpUtil {& & private static HttpClient httpClient =& & private static HttpGet httpG& & private static HttpPost httpP& & public static String TIME_OUT = &请求超时&;& & public static String SERVER_ERROR = &服务器异常&;& & public static String NETWORK_ERROR = &网络异常&;& & static {& & & & & & httpClient = getHttpClient();& & }& & /**& & &* Http Get请求 请求地址& & &*& & &* @param url & &Get参数& & &* @param params 编码& & &* @param encode 返回请求结果& & &* @return& & &* @throws org.apache.http.client.ClientProtocolException& & &* @throws java.io.IOException& & &*/& & public static String sendGetRequest(String url, Map&String, String& params,& & & & & & & & & & & & & & & & & & & & String encode) {& & & & String result =& & & & try {& & & & & & if (null == params) {& & & & & & & & httpGet = new HttpGet(url);& & & & & & } else {& & & & & & & & httpGet = new HttpGet(url + dealGetParams(params, encode));& & & & & & }& & & & & & HttpResponse response = httpClient.execute(httpGet);& & & & & & if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {& & & & & & & & result = EntityUtils.toString(response.getEntity());& & & & & & }& & & & } catch (ClientProtocolException e) {& & & & & & e.printStackTrace();& & & & } catch (IOException e) {& & & & & & e.printStackTrace();& & & & }& & & & return result != null ? result : &&;& & }& & public static String sendGetRequest(String url, Map&String, String& params)& & & & & & throws ClientProtocolException, IOException {& & & & return sendGetRequest(url, params, &UTF-8&);& & }& & public static String sendGetRequest(String url)& & & & & & throws ClientProtocolException, IOException {& & & & return sendGetRequest(url, null, &UTF-8&);& & }& & public static String sendGetRequestGB2312(String url)& & & & & & throws ClientProtocolException, IOException {& & & & return sendGetRequest(url, null, &GB2312&);& & }& & /**& & &* POST请求 返回请求结果 HashMap键值参数& & &*& & &* @param params& & &* @return& & &* @throws Exception& & &*/& & @SuppressWarnings({&deprecation&, &unchecked&})& & public static String sendPostRequest(String url, Object params, String encode) throws Exception {& & & & String resultStr =& & & & httpPost = new HttpPost(url);& & & & if (params != null) {& & & & & & StringE& & & & & & if (params instanceof Map) {& & & & & & & & entity = new StringEntity(dealPostParams(& & & & & & & & & & & & (HashMap&String, String&) params, encode));& & & & & & } else if (params instanceof String) {& & & & & & & & entity = new StringEntity((String) params, encode);& & & & & & } else if (params instanceof List) {& & & & & & & & entity = new UrlEncodedFormEntity(& & & & & & & & & & & & (List&? extends NameValuePair&) params, encode);& & & & & & } else {& & & & & & & & throw new Exception(&参数有误!&);& & & & & & }// & & & & & &httpPost.setHeader(&Authorization&,&Bearer access_token&);& & & & & & httpPost.setEntity(entity);& & & & }& & & & try {& & & & & & HttpResponse response = httpClient.execute(httpPost);& & & & & & if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {& & & & & & & & resultStr = EntityUtils.toString(response.getEntity());& & & & & & }& & & & } catch (ClientProtocolException e) {& & & & & & e.printStackTrace();& & & & } catch (IOException e) {& & & & & & e.printStackTrace();& & & & }& & & & return resultStr != null ? resultStr :& & }& & public static String sendPostRequest(String url) throws Exception {& & & & return sendPostRequest(url,&&);& & }& & /**& & &* 键值对请求 默认UTF-8编码& & &*& & &* @param url& & &* @param params& & &* @return& & &* @throws Exception& & &*/& & public static String sendPostRequest(String url, Map&String, String& params)& & & & & & throws Exception {& & & & return sendPostRequest(url, params, &UTF-8&);& & }& & /**& & &* String 默认UTF-8编码& & &*& & &* @param url& & &* @param params& & &* @return& & &* @throws Exception& & &*/& & public static String sendPostRequest(String url, String params)& & & & & & throws Exception {& & & & return sendPostRequest(url, params==null?null:params, &UTF-8&);& & }& & /**& & &* 键值对请求 默认UTF-8编码& & &*& & &* @param url& & &* @param params& & &* @return& & &* @throws Exception& & &*/& & public static String sendPostRequest(String url, List&NameValuePair& params)& & & & & & throws Exception {& & & & return sendPostRequest(url, params, &UTF-8&);& & }& & /**& & &* 处理Get方式请求的URL& & &*& & &* @param params& & &* @param enc& & &* @return& & &* @throws java.io.UnsupportedEncodingException& & &*/& & private static String dealGetParams(Map&String, String& params, String enc)& & & & & & throws UnsupportedEncodingException {& & & & StringBuffer sb = new StringBuffer();& & & & sb.append(&?&);& & & & for (Entry&String, String& entry : params.entrySet()) {& & & & & & // 参数名=参数&参数名=参数& & & & & & sb.append(entry.getKey()).append(&=&)& & & & & & & & & & .append(URLEncoder.encode(entry.getValue(), enc))& & & & & & & & & & .append(&&&);& & & & }& & & & // 删除最后一个&& & & & sb.deleteCharAt(sb.length() - 1);& & & & return sb.toString();& & }& & /**& & &* 处理POST请求URL& & &*& & &* @param params& & &* @param enc& & &* @return& & &*/& & private static String dealPostParams(Map&String, String& params, String enc) {& & & & StringBuffer sb = new StringBuffer();& & & & for (Entry&String, String& entry : params.entrySet()) {& & & & & & try {& & & & & & & & sb.append(entry.getKey()).append(&=&)& & & & & & & & & & & & .append(URLEncoder.encode(entry.getValue(), enc))& & & & & & & & & & & & .append(&&&);& & & & & & } catch (UnsupportedEncodingException e) {& & & & & & & & e.printStackTrace();& & & & & & }& & & & }& & & & sb.deleteCharAt(sb.length() - 1);& & & & return sb.toString();& & }& & /**& & &* 获取HttpClient& & &*& & &* @return& & &*/& & @SuppressWarnings(&deprecation&)& & public static synchronized HttpClient getHttpClient() {& & & & if (null == httpClient) {& & & & & & httpClient = new DefaultHttpClient();& & & & }& & & & return httpC& & }}最佳答案$.post(url, { json: postdata }, function (json) {if (json) {jBox.tip(&添加成功!&, &提示&);location.reload();}else {jBox.tip(&添加失败!&, &提示&);location.reload();}}, &json&)等等等等完等等等等等等等相关问答完完完完完完完完完完等等最近浏览暂无贡献等级暂无贡献等级暂无贡献等级暂无贡献等级暂无贡献等级暂无贡献等级暂无贡献等级暂无贡献等级暂无贡献等级扫描二维码关注最代码为好友"/>扫描二维码关注最代码为好友博客分类: public Raster2D dataView(String path) throws Exception{ Raster2D raster2D=RasterReadWrite.read(path); System.out.println(path); // Raster2D raster2D=new Raster2D(0, 0, 30, 10, 23, 9999, "hy"); 首先,看dataView是个wsdl描述服务的接口的一个具体:这里需要传递一个Raster2D这个实例,raster2D是个栅格数据,数据量比较大,在从服务端传递到客户端时,会出现,OutOfMeimery或Java heap 。。错误。 如何解决这一问题呢? 1.Axis2中是否有这个大数据量对象传递的方法,找了半天,自身查资料的能力有限,还是放弃了。 2.这跟我的在用SuperMap iClient开发时,发现查询的时候,数据量也很大,它是怎么实现的呢,于是查查资料,做了点功课。 public String dataView(String path) throws Exception{ Raster2D raster2D=RasterReadWrite.read(path); System.out.println(path); // Raster2D raster2D=new Raster2D(0, 0, 30, 10, 23, 9999, "hy"); [color=red] 将Raster2D转化为 json对象 JSONObject jsonObject = JSONObject.fromObject(raster2D); String rasterString=jsonObject .toString();[/color] 就这样做了个转换将对象转换为JSON对象,然后toString变成字符串,对于基本对象字符串的传递那自然木有什么大的问题咯。 接下来需要对在客户端解析Json对象,将数据利用起来。 ---(daixu) 浏览: 426899 次 来自: 上海 正解,问题解决了,要换tomcat的 大师,按照你的指点进行初始化工作,但是在connection. ... 您好 关于这个问题能描述得更详细一点吗? 找了半个小时了也没小号到m2e最新的地址,既然这个都让你找得这 ... 这个发的比较早了,现在在myeclipse中有自带的,ecli ... (window.slotbydup=window.slotbydup || []).push({ id: '4773203', container: s, size: '200,200', display: 'inlay-fix'博客分类: 某天,要做几个WebService,供第三方调用,一些是查询会返回多条数据,建议用分页,请求的时候带了条数,返回去的时候也带了条数,第三方不同意,让做最大条数限制,所以需要估算返回的最大条数。 1.读入XML计算一条数据所事的字节数据 public static void main(String args[]) { String FileName = "d:/aa.xml"; File myFile = new File(FileName); StringBuffer result = new StringBuffer(); BufferedReader in = new BufferedReader(new FileReader(myFile)); while ((str = in.readLine()) != null) { result.append(str); in.close(); } catch (IOException e) { e.getStackTrace(); String re=result.toString(); re=re.replaceAll("\\s*", ""); byte[] byteS=re.getBytes(); System.out.println(byteS.length); 结果4500B,即5K,由于这个XML的数据用XSD自动生成的,现实的数据肯定比这个复杂,由于有几个字段是1024B的,所以每条数据最大算10K 2. 有经验的人建议,Webservice每次传递的数据不要超过1M,因为0.5M相对于一个大的网页,再大就不能保证即时响应了,和带宽都有关系的。所以最终确定最大限制为50条数据,因为50条*10K=500K=0.5M。 qingfeng825 浏览: 529808 次 来自: 北京 这个女程序员厉害了。。。 可以通过WebService上传一个文件吗?素人派http:/ ... 写的不错嘛 可以做参考 谢谢,对我有帮助 com.smartdot.pdm.business.corp. ... (window.slotbydup=window.slotbydup || []).push({ id: '4773203', container: s, size: '200,200', display: 'inlay-fix'2015年2月 Java大版内专家分月排行榜第二2014年3月 Java大版内专家分月排行榜第二 2014年9月 Java大版内专家分月排行榜第三2014年6月 Java大版内专家分月排行榜第三2014年2月 Java大版内专家分月排行榜第三2013年11月 Java大版内专家分月排行榜第三2013年10月 Java大版内专家分月排行榜第三 匿名用户不能发表回复!| 每天回帖即可获得10分可用分!小技巧: 你还可以输入10000个字符 (Ctrl+Enter) 请遵守CSDN,不得违反国家法律法规。 转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。问题: webservice实现文件传输,并且接口参数要用XML格式数据,该怎么实现啊? 如题!要设计2个接口一个用于上传文件,接口参数传入XML格式数据;另一个接口实现下载文件,接口返回XML格式数据,客户端通过webservice返回的XML数据下载文件,怎么实现啊?解决方案1: 首先把上传xml序列化成字符串,在webservice服务端接收到字符串以后使用dom4j来解析XML,进行处理 Document&document&=&DocumentHelper.parseText(xmldata); Element&root&=&document.getRootElement(); 反过来也一样,生成你需要传递回去的XML文件,然后序列化成字符串,返回该字符串即可 解决方案2: 我的想法是,把文件上传到webservice客户端后,

我要回帖

更多关于 java集合底层数据结构 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信