本文整理汇总了Java中com.squareup.okhttp.HttpUrl.parse方法的典型用法代码示例。如果您正苦于以下问题:Java HttpUrl.parse方法的具体用法?Java HttpUrl.parse怎么用?Java HttpUrl.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.okhttp.HttpUrl
的用法示例。
在下文中一共展示了HttpUrl.parse方法的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();
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
};
}
示例5: 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);
}
示例6: shouldNotAggregatePathIfEmptinessSupplied
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
@Test
public void shouldNotAggregatePathIfEmptinessSupplied() throws Exception {
HttpUrl base = HttpUrl.parse("http://host/");
PathResolver resolver = new PathResolver.Builder()
.addPath("")
.build();
HttpUrl expected = resolver.resolve(base);
assertThat(expected, is(HttpUrl.parse("http://host/")));
PathResolver resolver2 = new PathResolver.Builder()
.addPaths("")
.build();
HttpUrl expected2 = resolver2.resolve(base);
assertThat(expected2, is(HttpUrl.parse("http://host/")));
}
示例7: testCreate4
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
@Test
public void testCreate4() {
RobinServiceFactory factory = mock(RobinServiceFactory.class, Mockito.CALLS_REAL_METHODS);
Credential credential = mock(Credential.class);
Client client = mock(Client.class);
HttpUrl endpoint = HttpUrl.parse("http://example.com");
RestAdapter.Builder builder = mock(RestAdapter.Builder.class, Mockito.CALLS_REAL_METHODS);
doReturn(builder).when(factory).getRestAdapterBuilder();
MockService service = factory.create(MockService.class, credential, client, endpoint);
assertThat(service).isNotNull();
verify(builder, times(1)).setRequestInterceptor(any(RequestInterceptor.class));
verify(builder, times(1)).setEndpoint(endpoint.toString());
}
示例8: doInBackground
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
/**
*
* @param params
* @return
*/
@Override
protected String doInBackground(Void... params) {
OkHttpClient client = new OkHttpClient();
HttpUrl httpUrl = HttpUrl.parse(TwitterSearchURL);
httpUrl = httpUrl.newBuilder()
.addQueryParameter("q", _searchTerm)
.addQueryParameter("lang", "en")
.addQueryParameter("result_type", "recent")
.build();
Request request = new Request.Builder()
.url(httpUrl)
.addHeader("Authorization", "Bearer " + _bearerToken)
.addHeader("Accept-Encoding", "gzip")
.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;
}
示例9: ensureValidUrl
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
private HttpUrl ensureValidUrl(String url) {
if (url == null) {
return null;
}
String safeUrl = url.startsWith("http") ? url : "https://" + url;
return HttpUrl.parse(safeUrl);
}
示例10: setUp
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
gson = new Gson();
url = HttpUrl.parse("http://domain.auth0.com");
factory = createBaseFactory();
}
示例11: shouldReturnAuthorizeUrl
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
@Test
public void shouldReturnAuthorizeUrl() throws Exception {
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN);
final HttpUrl url = HttpUrl.parse(auth0.getAuthorizeUrl());
assertThat(url, hasScheme("https"));
assertThat(url, hasHost(DOMAIN));
assertThat(url, hasPath("authorize"));
}
示例12: logIn
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
@OnClick(R.id.log_in_button)
@SuppressWarnings("unused")
public void logIn() {
showProgress(true);
String serverUrl = mServerUrl.getText().toString();
String username = mUsername.getText().toString();
String password = mPassword.getText().toString();
HttpUrl serverUri = HttpUrl.parse(serverUrl);
getDhisService().logInUser(
serverUri, new Credentials(username, password)
);
}
示例13: graphql
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
public Object graphql(String token, String query, Object variables) throws IOException, PlaylyfeException {
HttpUrl url = HttpUrl.parse(this.endPoint + "?access_token="+token);
System.out.println(url);
String req_body = gson.toJson(new GraphQLRequest(query, variables));
Request request = new Request.Builder()
.url(url)
.post(RequestBody.create(MEDIA_TYPE_JSON, req_body))
.build();
Response response = client.newCall(request).execute();
return parseJson(response.body().string());
}
示例14: shouldAggregateSinglePath
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
@Test
public void shouldAggregateSinglePath() throws Exception {
HttpUrl base = HttpUrl.parse("http://host/");
PathResolver resolver = new PathResolver.Builder()
.addPath("path")
.build();
HttpUrl expected = resolver.resolve(base);
assertThat(expected, is(HttpUrl.parse("http://host/path")));
}
示例15: shouldAggregateMultiplePaths
import com.squareup.okhttp.HttpUrl; //导入方法依赖的package包/类
@Test
public void shouldAggregateMultiplePaths() throws Exception {
HttpUrl base = HttpUrl.parse("http://host/");
PathResolver resolver = new PathResolver.Builder()
.addPaths("/path/a/b")
.build();
HttpUrl expected = resolver.resolve(base);
assertThat(expected, is(HttpUrl.parse("http://host/path/a/b")));
}