我正在使用翻新版本2.6.1通过网络发出http请求。我期望的JSON长42466个字符。但是,我只收到4073个字符,并且API在Web浏览器和邮递员上正常工作。
因此,我添加了自定义okhttp客户端并增加了超时时间,但这对我没有帮助。
private var okHttpClient: OkHttpClient = OkHttpClient().newBuilder()
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.build()
Run Code Online (Sandbox Code Playgroud)
然后,我尝试添加一个日志记录拦截器,发现okhttp在拦截器日志中以块的形式接收了我想要的响应。
private val httpInterceptor: HttpLoggingInterceptor = HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)
private var okHttpClient: OkHttpClient = OkHttpClient().newBuilder()
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.addInterceptor(httpInterceptor)
.build()
Run Code Online (Sandbox Code Playgroud)
最后,我将http客户端和拦截器分配给改造生成器,这就是它的外观
private val centralRetrofit = Retrofit.Builder().baseUrl("https://www.********.com/")
.addConverterFactory(ScalarsConverterFactory.create())
.client(okHttpClient)
.build()
.create(MusicAccess::class.java)
Run Code Online (Sandbox Code Playgroud)
因此,我认为使用发布请求将对我有所帮助,而不是尝试以字符串格式获取所有响应以检查响应
@Headers("Content-Type: text/html; charset=UTF-8")
@POST("**********")
fun getMusic(): Call<String>
Run Code Online (Sandbox Code Playgroud)
但是在我认为http响应将具有大小限制并使用阅读器通过以下方式从url访问json之后,也没有得出结论。
val client = OkHttpClient()
val request = Request.Builder().url("********")
.addHeader("Content-Type", "application/json")
.build()
val response = client.newCall(request).execute()
val input = response.body()?.byteStream()
val reader = BufferedReader(InputStreamReader(input)) …Run Code Online (Sandbox Code Playgroud) 我想在我的网站上发布一个包含WebView的应用程序.这就是整个应用程序.像移动Web应用程序,但来自商店.Apple/Google允许吗?
10倍
我已经集成了用于通知的 firebase-messaging 插件,但单击通知应用程序如果在后台或被杀死,则不会打开。我想在单击通知时打开应用程序。
下面是我的代码
void firebaseCloudMessagingListeners() {
FirebaseMessaging _firebaseMessaging = new FirebaseMessaging();
_firebaseMessaging.getToken().then((token){
print(token);
});
_firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true, badge: true, alert: true));
_firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings) {
print("Settings registered: $settings");
});
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
_showNotificationWithDefaultSound(message['notification']['body']);
print('on message $message');
return;
},
onResume: (Map<String, dynamic> message) async {
_showNotificationWithDefaultSound(message['data']['body']);
print('on message $message');
return;
},
onLaunch: (Map<String, dynamic> message) async {
_showNotificationWithDefaultSound(message['data']['body']);
print('on message $message');
},
);
}
_showNotificationWithDefaultSound(message) async {
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
new FlutterLocalNotificationsPlugin();
var android = …Run Code Online (Sandbox Code Playgroud)