के साथ रेट्रोफिट कैसे सेट करें मेरा एपीपाथ पूरी तरह गतिशील है। मेरे पास ऐसे क्षेत्र हैं जिनमें हमें "ipAddress" और "SSLprotocol" फ़ील्ड हैं। उन पर आधारित मैं अपने यूआरएल का निर्माण कर सकते हैं:कोई आधार यूआरएल
private String urlBuilder(Server server) {
String protocol;
String address = "";
if (AppTools.isDeviceOnWifi(activity)) {
address = serverToConnect.getExternalIp();
} else if (AppTools.isDeviceOnGSM(activity)) {
address = serverToConnect.getInternalIp();
}
if (server.isShouldUseSSL()) {
protocol = "https://";
} else {
protocol = "http://";
}
return protocol + address;
}
तो मेरी प्रोटोकॉल + पता हो सकता है: http: // + 192.168.0.01:8010 = http://192.168.0.01:8010
और मैं उस तरह इसका इस्तेमाल करना चाहते हैं:
@FormUrlEncoded
@POST("{fullyGeneratedPath}/json/token.php")
Observable<AuthenticationResponse> authenticateUser(
@Path("fullyGeneratedPath") String fullyGeneratedPath,
@Field("login") String login,
@Field("psw") String password,
@Field("mobile") String mobile);
authenticateUser के लिए तो पूरा पथ http://192.168.0.01:8010/json/token.php होगा - उदाहरण के लिए।
इसका मतलब है कि मुझे किसी भी बेसपैथ की आवश्यकता नहीं है क्योंकि मैं सर्वर पर निर्भर करता हूं कि मैं उस सर्वर पर निर्भर करता हूं जिसे मैं कनेक्ट करना चाहता हूं।
मेरे पुराना वापस सेटअप है:
@Provides
@Singleton
Retrofit provideRetrofit(OkHttpClient okHttpClient,
Converter.Factory converterFactory,
AppConfig appConfig) {
Retrofit.Builder builder = new Retrofit.Builder();
builder.client(okHttpClient)
.baseUrl(appConfig.getApiBasePath())
.addConverterFactory(converterFactory)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create());
return builder.build();
}
अगर मैं baseurl को दूर तो मैं त्रुटि है कि इस पैरामीटर के लिए आवश्यक है मिलता है। तो मैं करने के लिए मेरे apiBasePath सेट:
public String getApiBasePath() {
return "";
}
और फिर तुरंत बाद मैं पुराना वापस उदाहरण बनाने मैं त्रुटि मिलती है:
java.lang.IllegalArgumentException: Illegal URL:
इसे कैसे हल करने के लिए?
क्या यह आपको "http: //" को बेस यूआरएल के रूप में उपयोग करने देता है? – TheoKanning
हम्म नहीं, मुझे मिलता है: java.lang.IllegalArgumentException: अवैध यूआरएल: http: // – F1sher
आप @ यूआरएल एनोटेशन का उपयोग कर सकते हैं। लेकिन आपको हर यूआरएल को पूरी तरह से – Blackbelt