当前位置: 首页>>代码示例>>Java>>正文


Java HttpUrl类代码示例

本文整理汇总了Java中com.squareup.okhttp.HttpUrl的典型用法代码示例。如果您正苦于以下问题:Java HttpUrl类的具体用法?Java HttpUrl怎么用?Java HttpUrl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpUrl类属于com.squareup.okhttp包,在下文中一共展示了HttpUrl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: DynamicFeeLoader

import com.squareup.okhttp.HttpUrl; //导入依赖的package包/类
public DynamicFeeLoader(final Context context) {
    super(context);
    final PackageInfo packageInfo = WalletApplication.packageInfoFromContext(context);
    final int versionNameSplit = packageInfo.versionName.indexOf('-');
    this.dynamicFeesUrl = HttpUrl.parse(Constants.DYNAMIC_FEES_URL
            + (versionNameSplit >= 0 ? packageInfo.versionName.substring(versionNameSplit) : ""));
    this.userAgent = WalletApplication.httpUserAgent(packageInfo.versionName);
    this.assets = context.getAssets();
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:10,代码来源:DynamicFeeLoader.java

示例2: setup

import com.squareup.okhttp.HttpUrl; //导入依赖的package包/类
@Before
public void setup() {
    Robolectric.getBackgroundThreadScheduler().reset();
    Robolectric.getForegroundThreadScheduler().reset();
    ShadowLog.stream = System.out;
    activity = Robolectric.buildActivity(MockMainActivity.class).create().start().resume().visible().get();
    shadowOf(activity).grantPermissions("android.permission.INTERNET");
    server= new MockWebServer();
    try {
        server.start();
        HttpUrl url= server.url("/");
        UTConstants.REQUEST_BASE_URL_UT_V2 = url.toString();
        System.out.println(UTConstants.REQUEST_BASE_URL_UT_V2);
        ShadowSettings.setTestURL(url.toString());
        TestResponsesUT.setTestURL(url.toString());
    } catch (IOException e) {
        System.out.print("IOException");
    }
    bgScheduler = Robolectric.getBackgroundThreadScheduler();
    uiScheduler = Robolectric.getForegroundThreadScheduler();
    Robolectric.flushBackgroundThreadScheduler();
    Robolectric.flushForegroundThreadScheduler();
    bgScheduler.pause();
    uiScheduler.pause();
}
 
开发者ID:appnexus,项目名称:mobile-sdk-android,代码行数:26,代码来源:BaseRoboTest.java

示例3: authenticate

import com.squareup.okhttp.HttpUrl; //导入依赖的package包/类
public Request authenticate(Proxy proxy, Response response) throws IOException {
    List<Challenge> challenges = response.challenges();
    Request request = response.request();
    HttpUrl url = request.httpUrl();
    int size = challenges.size();
    for (int i = 0; i < size; i++) {
        Challenge challenge = (Challenge) challenges.get(i);
        if ("Basic".equalsIgnoreCase(challenge.getScheme())) {
            PasswordAuthentication auth = java.net.Authenticator
                    .requestPasswordAuthentication(url.host(), getConnectToInetAddress(proxy,
                            url), url.port(), url.scheme(), challenge.getRealm(), challenge
                            .getScheme(), url.url(), RequestorType.SERVER);
            if (auth != null) {
                return request.newBuilder().header("Authorization", Credentials.basic(auth
                        .getUserName(), new String(auth.getPassword()))).build();
            }
        }
    }
    return null;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:21,代码来源:AuthenticatorAdapter.java

示例4: getPermission

import com.squareup.okhttp.HttpUrl; //导入依赖的package包/类
public final Permission getPermission() throws IOException {
    int hostPort;
    URL url = getURL();
    String hostName = url.getHost();
    if (url.getPort() != -1) {
        hostPort = url.getPort();
    } else {
        hostPort = HttpUrl.defaultPort(url.getProtocol());
    }
    if (usingProxy()) {
        InetSocketAddress proxyAddress = (InetSocketAddress) this.client.getProxy().address();
        hostName = proxyAddress.getHostName();
        hostPort = proxyAddress.getPort();
    }
    return new SocketPermission(hostName + ":" + hostPort, "connect, resolve");
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:17,代码来源:HttpURLConnectionImpl.java

示例5: doInBackground

import com.squareup.okhttp.HttpUrl; //导入依赖的package包/类
/**
 *
 * @param params
 * @return
 */
@Override
protected String doInBackground(Void... params) {
    OkHttpClient client = new OkHttpClient();

    HttpUrl httpUrl = HttpUrl.parse(COIN_DESK_API_URL);
    //System.out.println("Requesting : " + httpUrl.toString());

    FormEncodingBuilder formBody = new FormEncodingBuilder();
    formBody.add("lastHours", "24");
    formBody.add("maxRespArrSize", "24");

    Request request = new Request.Builder()
            .url(httpUrl)
            .post(formBody.build())
            .build();

    String content = null;
    try {
        Response response = client.newCall(request).execute();
        ResponseBody body = response.body();

        if (isZipped(response)) {
            content = unzip(body);
        } else {
            content = body.string();
        }

        body.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return content;
}
 
开发者ID:ehanoc,项目名称:xwallet,代码行数:40,代码来源:CexChartAPI.java

示例6: onCreate

import com.squareup.okhttp.HttpUrl; //导入依赖的package包/类
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND);
    backgroundThread.start();
    backgroundHandler = new Handler(backgroundThread.getLooper());

    final PackageInfo packageInfo = application.packageInfo();
    final int versionNameSplit = packageInfo.versionName.indexOf('-');
    final HttpUrl.Builder url = HttpUrl
            .parse(Constants.VERSION_URL
                    + (versionNameSplit >= 0 ? packageInfo.versionName.substring(versionNameSplit) : ""))
            .newBuilder();
    url.addEncodedQueryParameter("package", packageInfo.packageName);
    url.addQueryParameter("current", Integer.toString(packageInfo.versionCode));
    versionUrl = url.build();
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:19,代码来源:AlertDialogsFragment.java

示例7: sessionInitShouldReturnSessionKey

import com.squareup.okhttp.HttpUrl; //导入依赖的package包/类
@Ignore("There is a problem in this test as the sessionKey gets updated by the integration tests and failing this tests.")
@Test
public void sessionInitShouldReturnSessionKey() throws IOException {
    HttpUrl baseUrl = server.url("/next/2/");

    JSONObject sessionInitRecorded = recordedResponses.sessionInit();
    server.enqueue(new MockResponse().setBody(sessionInitRecorded.toString()));

    Properties properties = resourceReader.getProperties("test.properties");
    properties.setProperty("baseurl", baseUrl.toString());

    Session session = new Session(properties);
    Login loginObject = session.getLoginObject();

    assertThat("The sessionkey from login object should match the recorded session key",
            loginObject.getSessionKey(), equalTo(sessionInitRecorded.getString("session_key")));

    assertThat("Only one request was made to the mock server",
            server.getRequestCount(), equalTo(1));
}
 
开发者ID:djonsson,项目名称:nordnet-next-api,代码行数:21,代码来源:TestSessionInit.java

示例8: generateGET

import com.squareup.okhttp.HttpUrl; //导入依赖的package包/类
String generateGET(Transaction transaction) {
    // Validate merchantId
    if (merchantId == null || merchantId.isEmpty()) {
        // The merchantId is required
        throw new Error("The merchantId is required", Error.ERROR_MISSING_MERCHANT_ID, null);
    }

    HttpUrl.Builder builder = new HttpUrl.Builder()
            .scheme(secure ? "https" : "http")
            .host(SERVER)
            .addPathSegment("merchants")
            .addPathSegment(merchantId);
    // Serialize query
    transaction.serialize(builder);
    Log.d(TAG, builder.build().query());
    return builder.build().url().toString();
}
 
开发者ID:scarabresearch,项目名称:EmarsysPredictSDKAndroid,代码行数:18,代码来源:Session.java

示例9: renewAuth

import com.squareup.okhttp.HttpUrl; //导入依赖的package包/类
/**
 * Requests new Credentials using a valid Refresh Token. The received token will have the same audience and scope as first requested. How the new Credentials are requested depends on the {@link Auth0#isOIDCConformant()} flag.
 * - If the instance is OIDC Conformant the endpoint will be /oauth/token with 'refresh_token' grant, and the response will include an id_token and an access_token if 'openid' scope was requested when the refresh_token was obtained.
 * - If the instance is not OIDC Conformant the endpoint will be /delegation with 'urn:ietf:params:oauth:grant-type:jwt-bearer' grant, and the response will include an id_token.
 * Example usage:
 * <pre>
 * {@code
 * client.renewAuth("{refresh_token}")
 *      .addParameter("scope", "openid profile email")
 *      .start(new BaseCallback<Credentials>() {
 *          {@literal}Override
 *          public void onSuccess(Credentials payload) { }
 *
 *          {@literal}@Override
 *          public void onFailure(AuthenticationException error) { }
 *      });
 * }
 * </pre>
 *
 * @param refreshToken used to fetch the new Credentials.
 * @return a request to start
 */
@SuppressWarnings("WeakerAccess")
public ParameterizableRequest<Credentials, AuthenticationException> renewAuth(@NonNull String refreshToken) {
    final Map<String, Object> parameters = ParameterBuilder.newBuilder()
            .setClientId(getClientId())
            .setRefreshToken(refreshToken)
            .setGrantType(auth0.isOIDCConformant() ? ParameterBuilder.GRANT_TYPE_REFRESH_TOKEN : ParameterBuilder.GRANT_TYPE_JWT)
            .asDictionary();

    HttpUrl url;
    if (auth0.isOIDCConformant()) {
        url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder()
                .addPathSegment(OAUTH_PATH)
                .addPathSegment(TOKEN_PATH)
                .build();
    } else {
        url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder()
                .addPathSegment(DELEGATION_PATH)
                .build();
    }

    return factory.POST(url, client, gson, Credentials.class, authErrorBuilder)
            .addParameters(parameters);
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:46,代码来源:AuthenticationAPIClient.java

示例10: resolveConfiguration

import com.squareup.okhttp.HttpUrl; //导入依赖的package包/类
private HttpUrl resolveConfiguration(@Nullable String configurationDomain, @NonNull HttpUrl domainUrl) {
    HttpUrl url = ensureValidUrl(configurationDomain);
    if (url == null) {
        final String host = domainUrl.host();
        if (host.endsWith(DOT_AUTH0_DOT_COM)) {
            String[] parts = host.split("\\.");
            if (parts.length > 3) {
                url = HttpUrl.parse("https://cdn." + parts[parts.length - 3] + DOT_AUTH0_DOT_COM);
            } else {
                url = HttpUrl.parse(AUTH0_US_CDN_URL);
            }
        } else {
            url = domainUrl;
        }
    }
    return url;
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:18,代码来源:Auth0.java

示例11: setUp

import com.squareup.okhttp.HttpUrl; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    HttpUrl url = HttpUrl.parse("https://auth0.com");
    parameterBuilder = ParameterBuilder.newBuilder();

    baseRequest = new BaseRequest<String, Auth0Exception>(url, client, new Gson(), adapter, errorBuilder, callback, headers, parameterBuilder) {
        @Override
        public String execute() throws Auth0Exception {
            return null;
        }

        @Override
        public void onResponse(Response response) throws IOException {

        }

        @Override
        protected Request doBuildRequest() throws RequestBodyBuildException {
            return null;
        }
    };
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:24,代码来源:BaseRequestTest.java

示例12: shouldSetRealm

import com.squareup.okhttp.HttpUrl; //导入依赖的package包/类
@Test
public void shouldSetRealm() throws Exception {
    HttpUrl url = HttpUrl.parse(mockAPI.getDomain())
            .newBuilder()
            .addPathSegment(OAUTH_PATH)
            .addPathSegment(TOKEN_PATH)
            .build();
    AuthenticationRequest req = createRequest(url);
    mockAPI.willReturnSuccessfulLogin();
    req.setRealm("users")
            .execute();

    final RecordedRequest request = mockAPI.takeRequest();
    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("realm", "users"));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:17,代码来源:BaseAuthenticationRequestTest.java

示例13: shouldWhiteListOAuth2ParametersOnLegacyEndpoints

import com.squareup.okhttp.HttpUrl; //导入依赖的package包/类
@Test
public void shouldWhiteListOAuth2ParametersOnLegacyEndpoints() throws Exception {
    HashMap<String, Object> parameters = new HashMap<>();
    parameters.put("extra", "value");
    parameters.put("realm", "users");
    HttpUrl url = HttpUrl.parse(mockAPI.getDomain())
            .newBuilder()
            .addPathSegment(OAUTH_PATH)
            .addPathSegment(RESOURCE_OWNER_PATH)
            .build();
    AuthenticationRequest req = createRequest(url);
    mockAPI.willReturnSuccessfulLogin();
    req.addAuthenticationParameters(parameters)
            .execute();

    final RecordedRequest request = mockAPI.takeRequest();
    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("extra", "value"));
    assertThat(body, not(hasKey("realm")));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:21,代码来源:BaseAuthenticationRequestTest.java

示例14: shouldWhiteListLegacyParametersOnNonLegacyEndpoints

import com.squareup.okhttp.HttpUrl; //导入依赖的package包/类
@Test
public void shouldWhiteListLegacyParametersOnNonLegacyEndpoints() throws Exception {
    HashMap<String, Object> parameters = new HashMap<>();
    parameters.put("extra", "value");
    parameters.put("connection", "my-connection");
    HttpUrl url = HttpUrl.parse(mockAPI.getDomain())
            .newBuilder()
            .addPathSegment(OAUTH_PATH)
            .addPathSegment(TOKEN_PATH)
            .build();
    AuthenticationRequest req = createRequest(url);
    mockAPI.willReturnSuccessfulLogin();
    req.addAuthenticationParameters(parameters)
            .execute();

    final RecordedRequest request = mockAPI.takeRequest();
    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("extra", "value"));
    assertThat(body, not(hasKey("connection")));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:21,代码来源:BaseAuthenticationRequestTest.java

示例15: get

import com.squareup.okhttp.HttpUrl; //导入依赖的package包/类
public Session get() {
    String serverUrlString = getString(SERVER_URI);
    String userNameString = getString(USERNAME);
    String passwordString = getString(PASSWORD);

    HttpUrl serverUrl = null;
    if (serverUrlString != null) {
        serverUrl = HttpUrl.parse(serverUrlString);
    }

    Credentials credentials = null;
    if (userNameString != null && passwordString != null) {
        credentials = new Credentials(
                userNameString, passwordString
        );
    }
    return new Session(serverUrl, credentials);
}
 
开发者ID:dhis2,项目名称:dhis2-android-dashboard,代码行数:19,代码来源:LastUpdatedManager.java


注:本文中的com.squareup.okhttp.HttpUrl类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。