Using Selenium how to get network request

后端 未结 3 831
隐瞒了意图╮
隐瞒了意图╮ 2020-12-07 23:43

I want to take all the network request using selenium..I am not getting any way to find this solution.If anyone can suggest me or provide code or library that will be apprec

3条回答
  •  死守一世寂寞
    2020-12-08 00:09

    1. You can use "browsermob-proxy", "LoggingPreferences", "CloseableHttpClient", "HttpURLConnection" for getting the logs
    2. If you wish not to use browser and want to get the response, then I would suggest to go for "CloseableHttpClient".
    3. Copy the URI ("www.somewebsite.com/v1/api/sign-in?"). Get the request payload(which will be available in that particular API URI). Pass all the parameters with "&" like this "www.somewebsite.com/v1/api/sign-in?&username=xyz&password=1234566&app_id=12123214324234134&app_secret=213242345345345" (Remember app id and app secret is very unique and do not expose it anywhere)
    4. Once you get the URI, this code will give you JSON format response
                HttpPost request = new HttpPost(str);
                request.setHeader("content-type", "application/json");
                HttpResponse response = client.execute(request);
                BufferedReader bufReader = new BufferedReader(new InputStreamReader(
                        response.getEntity().getContent()));
                while ((line = bufReader.readLine()) != null) {
                    builder=String.valueOf(line);
                }
    
                System.out.println(builder);
            }
    
    

提交回复
热议问题