【发布时间】:2017-09-03 15:58:58
【问题描述】:
我遇到了一个问题,我想向 linkit 7697 发送 GET 请求。
当我通过 chrome 和 postman 请求时,它工作完美。
这是邮递员的快照
截图:
我认为请求不需要任何请求标头或正文,响应将是纯 html text/html。
但我失败了,低于日志
D/OkHttp: --> GET http://192.168.0.7/F http/1.1
D/OkHttp: --> END GET
D/OkHttp: <-- HTTP FAILED: java.net.SocketTimeoutException: connect timed out
下面是我的安卓代码:
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging).connectTimeout(10, TimeUnit.SECONDS);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://192.168.0.7/")
.addConverterFactory(GsonConverterFactory.create())
.addConverterFactory(ScalarsConverterFactory.create()).
client(httpClient.build()).build();
Call<ResponseBody> call = retrofit.create(LinkltApi.class).requestTurn();
call.enqueue(callback);
@GET("/F")
Call<ResponseBody> requestTurn();
感谢您的宝贵时间 :)
【问题讨论】:
-
尝试将连接超时时间增加到 60 而不是 10。
-
在屏幕截图中您请求的是
/R,而在代码中它是/F,这样可以吗? -
/R, /F 在邮递员中工作,只是不同的API,但完全一样
-
您正在真实设备或模拟器上进行测试。使用手机的 chrome 并请求相同。看看它是否工作
-
我用的是真机,在手机的chrome上可以用。