我正在尝试从服务器获取响应,但是禁止returinig 403,但是在apitester.com上测试api可以正常工作。
这是我要求get方法的代码:
public void getResponse(Context context) throws IOException {
OkHttpClient client = new OkHttpClient();
Hmac hmac = new Hmac();
String auth = hmac.txt;
String url = "https://api.hotstar.com/h/v1/play?contentId=1000034502";
Request request = new Request.Builder()
.url(url)
.addHeader("hotstarauth",auth)
.addHeader("referer","https://hotstar.com/movies/2-states/1000034502")
.addHeader("x-country-code","IN")
.addHeader("x-platform-code","TABLET")
.addHeader("x-region-code","undefined")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Toast.makeText(context, "Error Occured", Toast.LENGTH_SHORT).show();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
Log.d("Server Responded: ", response.toString());
}
});
}
作为回应,我被禁止了403
但是在apitester.com上使用相同的配置就可以了! 这是apitester https://www.apitester.com/shared/checks/dca814bb92fb40af8aecda95cdf2f39c
上的sharedconig为什么我没有在android上得到响应?