[Android] Open source framework xutils httputils proxy settings (temporary redirect error)

Source: Internet
Author: User

A simple study of the use of xutils today

Https://github.com/wyouflf/xUtils

When using the Httputils module, the temporary Redirect error is always found.

Look at the source code and find that if you are using a proxy to go online, you need to pass the proxy string value when initializing the httputils.

In the Httputils.java:

     Public Httputils (int  conntimeout, String useragent) {        new  basichttpparams ();        Connmanagerparams.settimeout (params, conntimeout);        Httpconnectionparams.setsotimeout (params, conntimeout);        Httpconnectionparams.setconnectiontimeout (params, conntimeout);         if (Textutils.isempty (useragent)) {            = otherutils.getuseragent (null);        }        Httpprotocolparams.setuseragent (params, useragent);

So, workaround one, call the constructor method that needs to be proxied to instantiate the httputils.

     Public httputils (String useragent) {        this(httputils.default_conn_timeout, useragent);    }

However, in many cases, we do not need to know these, because different environments may require different proxy settings.

Workaround two, directly comment out the code that sets the agent

     Public Httputils (int  conntimeout, String useragent) {        new  basichttpparams ();        Connmanagerparams.settimeout (params, conntimeout);        Httpconnectionparams.setsotimeout (params, conntimeout);        Httpconnectionparams.setconnectiontimeout (params, conntimeout);         if (Textutils.isempty (useragent)) {            = otherutils.getuseragent (null);        }         // httpprotocolparams.setuseragent (params, useragent);

In this way, you do not need to consider the proxy settings at this level of code.

[Android] Open source framework xutils httputils proxy settings (temporary redirect error)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.