requestmethod post和get_post与get

requestmethod post和get_post与get一、GetMethodtry{HttpClientclient=newHttpClient();StringOrderId_url="http://api.t.sina.com.cn/short_url/shorten.json?source=3271760578&url_long="+req.ge…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

一、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"));
    }
}

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/193294.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号