Skip to content

Commit a50bc76

Browse files
committed
优化:方法:sync()、async() 与 baseUrl() 传入的 URL 自动 trim
1 parent a71f721 commit a50bc76

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

‎okhttps/src/main/java/com/ejlchina/okhttps/HTTP.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ public Builder config(OkConfig config) {
212212
* @return Builder
213213
*/
214214
public Builder baseUrl(String baseUrl) {
215-
this.baseUrl = baseUrl;
215+
if (baseUrl != null) {
216+
this.baseUrl = baseUrl.trim();
217+
}
216218
return this;
217219
}
218220

‎okhttps/src/main/java/com/ejlchina/okhttps/internal/HttpClient.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ private String urlPath(String urlPath, boolean websocket) {
328328
throw new HttpException("在设置 BaseUrl 之前,您必须指定具体路径才能发起请求!");
329329
}
330330
} else {
331+
urlPath = urlPath.trim();
331332
boolean isFullPath = urlPath.startsWith("https://")
332333
|| urlPath.startsWith("http://")
333334
|| urlPath.startsWith("wss://")
@@ -337,7 +338,7 @@ private String urlPath(String urlPath, boolean websocket) {
337338
} else if (baseUrl != null) {
338339
fullUrl = baseUrl + urlPath;
339340
} else {
340-
throw new HttpException("在设置 BaseUrl 之前,您必须使用全路径URL发起请求,当前URL为:" + urlPath);
341+
throw new HttpException("在设置 BaseUrl 之前,您必须使用全路径URL发起请求,当前URL为:'" + urlPath + "'");
341342
}
342343
}
343344
if (websocket && fullUrl.startsWith("http")) {

0 commit comments

Comments
 (0)