天过无痕 2019-11-06 01:14 采纳率: 0%
浏览 3950
已采纳

测试报错,Connection refused: connect,求解?

代码:

public class ItfTest {

    /**
     * @param args
     */
    public static void main(String[] args) {


        try {
            String out = testbiz();

            System.out.println(out);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }



    public static String testbiz() throws HttpException, IOException {
        HttpClient httpClient = new HttpClient();
        PostMethod post = new PostMethod( "http://localhost:8001/itf/OI_AddSaleByParameter");
       //  PostMethod post = new PostMethod( "https://rryx.sinovatech.com/itf/OI_QueryEShopOrder");        
        post.setRequestHeader("Content-Type",
                "application/x-www-form-urlencoded;charset=utf-8");
        String key = "123321abc";
       String channel="ch_shenxun";
        Map<String, Object> req = new HashMap<>();
       String instr ="{\"body\": \"{\\\"startTime\\\":\\\"2019-01-01 14:43:19\\\",\\\"endTime\\\":\\\"2019-01-12 15:14:42\\\",\\\"phone\\\":\\\"18309858042\\\"}\",\"head\": {} }";
       /* String instr ="6351";
        req.put("loginCode",instr);*/
        Map<String, Object> header = new HashMap<>();
        header.put("appId", channel);
        header.put("tid", UUID.randomUUID().toString());
        header.put("timestamp", System.currentTimeMillis());
        header.put("ver", "1.0");
        Map<String, Object> reMap = new HashMap<>();
        reMap.put("header", header);
        reMap.put("req", req);

        req.put("saleName","123");
        req.put("goodIds","ff8080815e562c4d015e6103956700b6");
        req.put("orderValue","1");
        req.put("createName","管理员");


        System.out.println(JSONObject.toJSON(reMap));
        String reqdata = JSONObject.toJSONString(reMap);
        String sign = DigestUtils.md5Hex(reqdata + key);

        NameValuePair[] param = { new NameValuePair("sign", sign),
                new NameValuePair("reqdata", reqdata) };
        post.setRequestBody(param);
        int result = httpClient.executeMethod(post);
        System.out.println("返回结果=" + result);
        InputStream in = post.getResponseBodyAsStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));

        StringBuilder sb = new StringBuilder();
        String line = reader.readLine();
        while (line != null) {
            sb.append(line);
            line = reader.readLine();
        }
        reader.close();

        return sb.toString();
    }

}
//以上代码传参测试,但是运行后报错
java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at java.net.Socket.connect(Socket.java:538)
    at java.net.Socket.<init>(Socket.java:434)
    at java.net.Socket.<init>(Socket.java:286)
    at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
    at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:122)
    at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
    at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
    at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
    at com.sinovatech.test.ItfTest.testbiz(ItfTest.java:95)
    at com.sinovatech.test.ItfTest.main(ItfTest.java:52)
    求大神指点

展开全部

  • 写回答

2条回答 默认 最新

  • 毕小宝 博客专家认证 2019-11-06 01:16
    关注

    说明端口没有启动,确认一下 http://localhost:8001 应用是否已经启动。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 加热反应炉PLC控制系统设计(相关搜索:梯形图)
  • ¥15 python 用Dorc包报错,我的写法和网上教的是一样的但是它显示无效参数,是什么问题
  • ¥15 指定IP电脑的访问设置
  • ¥30 matlab ode45 未发现警告,但是运行出错
  • ¥15 vscode platformio
  • ¥15 代写uni代码,app唤醒
  • ¥15 全志t113i启动qt应用程序提示internal error
  • ¥15 ensp可以看看嘛.
  • ¥80 51单片机C语言代码解决单片机为AT89C52是清翔单片机
  • ¥60 优博讯DT50高通安卓11系统刷完机自动进去fastboot模式
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部