有大佬能帮忙看看 Java 怎么获取这个网址返回的数据吗? https://steamcommunity.com/inventory/76561198426206369/730/2?l=chinese&count=5000 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
wzx155
V2EX    Steam

有大佬能帮忙看看 Java 怎么获取这个网址返回的数据吗? https://steamcommunity.com/inventory/76561198426206369/730/2?l=chinese&count=5000

  •  
  •   wzx155 2021-03-12 12:14:33 +08:00 2718 次点击
    这是一个创建于 1674 天前的主题,其中的信息可能已经有所发展或是发生改变。
    9 条回复    2022-06-30 16:50:36 +08:00
    lu5je0
        1
    lu5je0  
       2021-03-12 12:18:49 +08:00 via Android
    steam 有现成的 api 。多看看文档
    rabbirbot00
        2
    rabbirbot00  
       2021-03-12 15:46:21 +08:00
    如果你的连返回的 JSON 数据都拿不到报超时的话,是因为 steamcommunity.com 是 Steam 社区的地址,在国内是没法直接访问的,之前我做毕设的时候就遇到了这个问题,如果你要在 Java 项目中访问只能走代理分流或者用国外服务器反代。
    wzx155
        3
    wzx155  
    OP
       2021-03-12 16:25:51 +08:00
    @rabbirbot00
    为什么我开 fq 软件后浏览器可以并收到返回的获取数据,但是在 java 项目中连接超时呢?
    Boyizmen
        4
    Boyizmen  
       2021-03-12 17:05:03 +08:00
    #3 你的 java client 也需要设置 proxy 的
    rabbirbot00
        5
    rabbirbot00  
       2021-03-12 17:43:32 +08:00
    @wzx155 楼上的方法我不清楚具体做法,我当时是确定本地代理在哪个端口上,比方说如果在 1080 端口的话,就在访问接口的那段 Java 代码里加上代理信息 {"http:":"127.0.0.1:1080", "https:":"127.0.0.1:1080"} 这样最后打出的 JAR 包在本机跑也不会有问题。
    wzx155
        7
    wzx155  
    OP
       2021-03-12 18:37:34 +08:00
    @rabbirbot00

    大佬我买了个国外的 ip 设置了代理,连接到是不超时了,现在又 Connection reset 了

    package com.example.demo;
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpHost;
    import org.apache.http.client.ResponseHandler;
    import org.apache.http.client.config.RequestConfig;
    import org.apache.http.client.methods.CloseableHttpResponse;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.impl.client.CloseableHttpClient;
    import org.apache.http.impl.client.HttpClients;
    import org.apache.http.util.EntityUtils;
    import org.junit.jupiter.api.Test;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.http.ResponseEntity;
    imprt java.io.IOException;
    import java.nio.charset.StandardCharsets;

    @SpringBootTest
    class DemoApplicationTests {
    @Test
    public void testGet1() {
    CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
    String urlStr = "https://steamcommunity.com/profiles/76561198426206369/inventory/json/730/2";
    HttpGet httpGet = new HttpGet(urlStr);
    httpGet.addHeader("User-Agent" ,"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36 Edg/89.0.774.45");
    ResponseHandler responseHandler;
    String ip = "150.109.186.75";
    int port = **;
    HttpHost proxy = new HttpHost(ip, port);
    RequestConfig requestCOnfig= RequestConfig.custom().setProxy(proxy).build();
    httpGet.setConfig(requestConfig);
    CloseableHttpResponse respOnse= null;
    try {
    respOnse= closeableHttpClient.execute( httpGet);
    HttpEntity entity = response.getEntity();
    String s = EntityUtils.toString(entity, StandardCharsets.UTF_8);
    System.out.println(s);
    EntityUtils.consume(entity);
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    if (closeableHttpClient != null) {
    try {
    closeableHttpClient.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    if (response != null) {
    try {
    response.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }
    }
    }


    2021-03-12 18:29:08.185 INFO 17188 --- [ main] o.apache.http.impl.execchain.RetryExec : I/O exception (java.net.SocketException) caught when processing request to {tls}->http://150.109.186.75:**->https://steamcommunity.com:443: Connection reset
    2021-03-12 18:29:08.185 INFO 17188 --- [ main] o.apache.http.impl.execchain.RetryExec : Retrying request to {tls}->http://150.109.186.75:6396->https://steamcommunity.com:443
    2021-03-12 18:29:08.280 INFO 17188 --- [ main] o.apache.http.impl.execchain.RetryExec : I/O exception (java.net.SocketException) caught when processing request to {tls}->http://150.109.186.75:**->https://steamcommunity.com:443: Connection reset
    2021-03-12 18:29:08.280 INFO 17188 --- [ main] o.apache.http.impl.execchain.RetryExec : Retrying request to {tls}->http://150.109.186.75:6396->https://steamcommunity.com:443
    2021-03-12 18:29:08.382 INFO 17188 --- [ main] o.apache.http.impl.execchain.RetryExec : I/O exception (java.net.SocketException) caught when processing request to {tls}->http://150.109.186.75:**->https://steamcommunity.com:443: Connection reset
    2021-03-12 18:29:08.382 INFO 17188 --- [ main] o.apache.http.impl.execchain.RetryExec : Retrying request to {tls}->http://150.109.186.75:6396->https://steamcommunity.com:443

    java.net.SocketException: Connection reset
    rabbirbot00
        8
    rabbirbot00  
       2021-03-13 22:04:40 +08:00
    @wzx155 老代码也找不到了不记得当时怎么写的了,没有响应码的话没法确定是哪里的问题,但是一般来说都是 Steam 强制 HTTP 跳转到 HTTPS 了,拿到响应代码看看呢
    ql562482472
        9
    ql562482472  
       2022-06-30 16:50:36 +08:00
    你的 proxy 不对呗 指不定是 socks5 被你当成 http 的调了
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2688 人在线   最高记录 6679 &nbp;     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 23ms UTC 14:08 PVG 22:08 LAX 07:08 JFK 10:08
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86