zoukankan      html  css  js  c++  java
  • PostMethod和GetMethod用法

    注:新浪短接口参考地址:https://www.douban.com/note/249723561/      将长的url链接转换成短链接

    一、GetMethod

    try {
    						
    	HttpClient client = new HttpClient();
    	String OrderId_url ="http://api.t.sina.com.cn/short_url/shorten.json?source=3271760578&url_long="+req.getScheme()+"://"+ req.getServerName()+req.getContextPath()+"/wx/showWxOrderDetail.do?orderId="+thirdPayLogDetail.getSaleOrderSysId();
    	GetMethod get = new GetMethod(OrderId_url);						        
         get.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
    	int status = client.executeMethod(get);
    	String res = get.getResponseBodyAsString().trim();
    	System.out.println("返回回来的数据:"+res+ "  状态值:" + status);
    	//返回回来的数据:[{"url_short":"http://t.cn/RONu69s","url_long":"http://dev7.89t.cn/ebusiness/wx/showWxOrderDetail.do?orderId=12451","type":0}]  状态值:200						
    	JSONArray result=JSONArray.fromObject(res);//转json对象
    	JSONObject getJsonObj = result.getJSONObject(0);
    	int type = (int) getJsonObj.get("type");
    	String url_short = getJsonObj.getString("url_short");
    	System.out.println("返回状态:"+type+"=======短接口:"+url_short);
    

     二、PostMethod

    		HttpClient client = new HttpClient();
    		String methodName="temporaryOrder.do";
    		String serverUrl=
    		PostMethod post = new PostMethod(serverUrl);
    		post.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");		
    		try {
    			int status = client.executeMethod(post);
    			String response = post.getResponseBodyAsString().trim();
    			System.out.println("返回回来的数据:"+response);
    			if (logger.isInfoEnabled()) {
    				logger.info("返回信息:" + response + "  状态值:" + status);
    			}
    			JSONObject result=JSONObject.fromObject(response);//转json对象
    			JSONObject headOb=result.getJSONObject("head");//头部信息
    			JSONObject resultBody=result.getJSONObject("body");
    			if (response.contains(""code":"200"")) {//请求成功
    				//TODO 记录订单明细号
    				if (resultBody.has("orderDetail")) {
    
    				}
    				return true;
    			}else{
    				throw new BusinessException(headOb.getString("msg"));
    			}
    

      

  • 相关阅读:
    在购物过程中的购买用请求重定向不用转发的原因
    自己在WEB学习过程中遇到的问题
    WEB应用中普通java代码如何读取资源文件
    [课堂总结]C++课堂总结(二)
    [一些问题] ubuntu 18.04下 配置qt opencv的坑
    [学习笔记] Ubuntu下编译C++ OpenCV程序并运行
    [学习笔记] cv2.Canny 边缘检测
    [C++讨论课] 课堂记录(一)
    [R] 简单笔记(一)
    Appium入门示例(Java)
  • 原文地址:https://www.cnblogs.com/guzhou-ing/p/7665888.html
Copyright © 2011-2022 走看看