private void a(URL url, String s)
 {
     Context context = (Context)c.get();
     HttpURLConnection httpurlconnection = (HttpURLConnection)url.openConnection();
     httpurlconnection.setRequestMethod("POST");
     int i = s.getBytes().length;
     httpurlconnection.setRequestProperty("Content-Length", (new StringBuilder()).append(i).append("").toString());
     httpurlconnection.setDoOutput(true);
     OutputStreamWriter outputstreamwriter = new OutputStreamWriter(httpurlconnection.getOutputStream());
     outputstreamwriter.write(s);
     outputstreamwriter.close();
     Log.i("AppsFlyer", (new StringBuilder()).append("response code: ").append(httpurlconnection.getResponseCode()).toString());
     AppsFlyerLib.a("response from server. status=", Integer.toString(httpurlconnection.getResponseCode()), context);
     if (httpurlconnection.getResponseCode() == 200 && c.get() != null)
     {
         SharedPreferences sharedpreferences = context.getSharedPreferences("appsflyer-data", 0);
         android.content.SharedPreferences.Editor editor = sharedpreferences.edit();
         editor.putString("sentSuccessfully", "true");
         editor.putInt("appsFlyerCount", 1 + sharedpreferences.getInt("appsFlyerCount", 1));
         editor.commit();
     }
 }
 static void finest(Exception e) {
   PlatformLogger logger = HttpURLConnection.getHttpLogger();
   if (logger.isLoggable(PlatformLogger.Level.FINEST)) {
     logger.finest("NTLMAuthenticationProxy: " + e);
   }
 }
Exemplo n.º 3
0
  public static void main(String[] args) {
    System.setProperty(
        "webdriver.chrome.driver", "D:\\selenium\\chromedriver_win32\\chromedriver.exe");
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--user-agent=iphone");
    WebDriver driver = new ChromeDriver(options);
    driver.manage().window().maximize();
    Navigation navigation = driver.navigate();
    navigation.to("https://www.touchouwang.net/");

    File file = new File("D:\\testlog.txt");
    if (!file.exists()) {
      try {
        file.createNewFile();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    FileWriter log = new FileWriter(file, true);

    SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    log.write("------------------------------------------------------------------------------\r\n");
    log.write("\r\n\r\n\r\n");
    log.write("移动端首页\r\n");

    // case1:banner、列表图片加载
    log.write("case1:banner、列表图片加载\r\n");
    String banner =
        driver.findElement(By.xpath("//*[@id='swiper']/div[1]/div[3]/a/img")).getAttribute("src");
    URL banner_url = new URL(banner);
    try {
      HttpURLConnection uConnection = (HttpURLConnection) banner_url.openConnection();
      if (uConnection.getResponseCode() == 200) {
        log.write(time.format(new Date()) + "   首页banner加载成功!\r\n");
      } else {
        log.write("报错:首页banner加载失败!\r\n");
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    for (int i = 1; i < 4; i++) {
      String xpath1 = "/html/body/article[";
      String xpath2 = i + "";
      String xpath3 = "]/div[2]/img";
      String newxpath = xpath1 + xpath2 + xpath3;
      String list_pic1 = driver.findElement(By.xpath(newxpath)).getAttribute("src");
      URL list_pic1_url = new URL(list_pic1);
      try {
        HttpURLConnection uConnection2 = (HttpURLConnection) list_pic1_url.openConnection();
        if (uConnection2.getResponseCode() == 200) {
          log.write(time.format(new Date()) + "   首页项目列表第" + i + "张图加载成功\r\n");
        } else {
          log.write("报错:首页项目列表第" + i + "张图加载失败\r\n");
        }
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }