2
我使用okhttp从我的Android APK发送一些http请求。由于某些服务器端代理的要求,我希望url端点类似于:“https://api.example.com”,但是在http请求中,我想将HOST头部覆盖为“Host:proxy.example.com”。我试图用这样的:在okhttp请求中覆盖HOST头
HttpUrl url = new HttpUrl.Builder()
.scheme("https")
.host("api.example.com")
.build();
okhttprequest = new com.squareup.okhttp.Request.Builder()
.url(url)
.method("GET", requestBody)
.header("Host", "proxy.example.com")
.build();
response = mOkHttpClient.newCall(okhttprequest).execute();
然而,当我看着在网络数据包的HTTP请求,HOST头还是“api.example.com”。只是想知道,我可以覆盖HOST头的任何建议?非常感谢!
感谢您的回复。我试图使用网络拦截器,但它仍然没有工作...似乎okhttp只是不希望主机头被改变为不同于端点url ... – Bob