Exemplo n.º 1
0
  @SmallTest
  public void testPost2() throws Throwable {

    httpManager.asyncPost(
        "http://up.qiniu.com",
        "hello".getBytes(),
        null,
        null,
        new CompletionHandler() {
          @Override
          public void complete(ResponseInfo rinfo, JSONObject response) {
            Log.d("qiniutest", rinfo.toString());
            info = rinfo;
            signal.countDown();
          }
        },
        null);

    try {
      signal.await(60, TimeUnit.SECONDS); // wait for callback
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    Assert.assertNotNull(info.reqId);
  }
Exemplo n.º 2
0
  @SmallTest
  public void testPostNoPort() throws Throwable {

    httpManager.asyncPost(
        "http://up.qiniu.com:12345",
        "hello".getBytes(),
        null,
        null,
        new CompletionHandler() {
          @Override
          public void complete(ResponseInfo rinfo, JSONObject response) {
            Log.d("qiniutest", rinfo.toString());
            info = rinfo;
            signal.countDown();
          }
        },
        null);

    try {
      signal.await(60, TimeUnit.SECONDS); // wait for callback
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    Assert.assertEquals("", info.reqId);
    Assert.assertTrue(
        ResponseInfo.CannotConnectToHost == info.statusCode
            || ResponseInfo.TimedOut == info.statusCode);
  }
Exemplo n.º 3
0
  @SmallTest
  public void testPostIP() throws Throwable {
    StringMap x = new StringMap().put("Host", "www.qiniu.com");
    httpManager.asyncPost(
        "http://183.136.139.12/",
        "hello".getBytes(),
        x,
        null,
        new CompletionHandler() {
          @Override
          public void complete(ResponseInfo rinfo, JSONObject response) {
            Log.d("qiniutest", rinfo.toString());
            info = rinfo;
            signal.countDown();
          }
        },
        null);

    try {
      signal.await(60, TimeUnit.SECONDS); // wait for callback
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    Assert.assertNotNull(info.reqId);
    Assert.assertEquals(200, info.statusCode);
  }
Exemplo n.º 4
0
 private void post(
     URI uri,
     byte[] data,
     int offset,
     int size,
     ProgressHandler progress,
     CompletionHandler completion,
     UpCancellationSignal c) {
   client.asyncPost(uri.toString(), data, offset, size, headers, progress, completion, c);
 }