2

Headers are used with request queries in a php script.

I want to use the same headers in retrofit or Okhttp in android, but I don't know what to write instead of headers written in php.

Here are the headers I want to use in android written in php:

function init_ch($u)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, TRUE);
    curl_setopt($ch, CURLOPT_NOBODY, TRUE);
    curl_setopt($ch, CURLOPT_URL, $u);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile Safari/537.3");
    curl_setopt($ch, CURLOPT_REFERER, $u);
    curl_setopt($ch, CURLOPT_ACCEPT_ENCODING, "utf-8,cp1251");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    return $ch;
}

I have no idea what to write instead of these headers, can you help with this?

spo spo
  • 21
  • 2
  • Have you read this question: https://stackoverflow.com/questions/26509107/how-to-specify-a-default-user-agent-for-okhttp-2-x-requests – Zak Mar 15 '22 at 22:54
  • I could only see User-Agent. How should I find the others? @Zak – spo spo Mar 15 '22 at 22:56
  • See https://square.github.io/okhttp/recipes/#accessing-headers-kt-java for OkHttp and the "Headers Manipulation" section in https://square.github.io/retrofit/ for Retrofit. – CommonsWare Mar 15 '22 at 23:10
  • @CommonsWare -- I think this question is so specific, and extremely difficult to search out -- In addition to the fact that is a great link .. If OP agrees that your comment solves his issue, you may consider answering for the SEO benefit of future askers of the same question. – Zak Mar 15 '22 at 23:29
  • These resources seem useful, but I have not been able to reach my goal. – spo spo Mar 16 '22 at 06:03

0 Answers0