On okhttp removing request header user agent

User agent of HTTP header

The Chinese name of user agent is user agent. It is a part of HTTP protocol and belongs to the header domain. The user agent page is referred to as UA for short. It is a special string header. It is an identification that wants to visit the website to provide information such as the browser type and version, operating system and version, browser kernel, etc. the website visited by users can display different typesetting, so as to provide users with better experience or information statistics

Phenomenon description

When requesting HTTP requests with okhttp framework, the user agent will be brought; However, sometimes we need to remove the user agent from the request header;

Client program:

Return result:

You will find: "user agent": "okhttp / 3.4.1". This is because the built-in interceptor bridgeinterceptor of okhttp is added by default. We need to use the network interceptor to re intercept the request header;

resolvent:

Using interceptor to delete user agent

Then use the network interceptor to set the custom interceptor loginterceptor:

Finally, resend the network request:

Description: the interface postparam returns all parameters and request header information of the request. The code will not be displayed.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>