kandi background
Explore Kits

okhttputils | okhttp的辅助类

 by   hongyangAndroid Java Version: Current License: Apache-2.0

 by   hongyangAndroid Java Version: Current License: Apache-2.0

Download this library from

kandi X-RAY | okhttputils Summary

okhttputils is a Java library. okhttputils has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has medium support. You can download it from GitHub.
[停止维护]okhttp的辅助类
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • okhttputils has a medium active ecosystem.
  • It has 6861 star(s) with 2419 fork(s). There are 417 watchers for this library.
  • It had no major release in the last 12 months.
  • okhttputils has no issues reported. There are 8 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of okhttputils is current.
okhttputils Support
Best in #Java
Average in #Java
okhttputils Support
Best in #Java
Average in #Java

quality kandi Quality

  • okhttputils has 0 bugs and 0 code smells.
okhttputils Quality
Best in #Java
Average in #Java
okhttputils Quality
Best in #Java
Average in #Java

securitySecurity

  • okhttputils has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • okhttputils code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
okhttputils Security
Best in #Java
Average in #Java
okhttputils Security
Best in #Java
Average in #Java

license License

  • okhttputils is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
okhttputils License
Best in #Java
Average in #Java
okhttputils License
Best in #Java
Average in #Java

buildReuse

  • okhttputils releases are not available. You will need to build from source code and install.
  • Build file is available. You can build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
okhttputils Reuse
Best in #Java
Average in #Java
okhttputils Reuse
Best in #Java
Average in #Java
Top functions reviewed by kandi - BETA

kandi has reviewed okhttputils and discovered the below as its top functions. This is intended to give you an instant insight into okhttputils implemented functionality, and help decide if they suit your requirements.

  • Called when view is changed .
  • Save file .
  • Generate certificate manager .
  • generate response log for response
  • Downloads a file
  • Gets view height .
  • Add cookies .
  • On create .
  • Build request body .
  • Build call .

okhttputils Key Features

[停止维护]okhttp的辅助类

用法

copy iconCopydownload iconDownload
	compile 'com.zhy:okhttputils:2.6.2'

配置OkhttpClient

copy iconCopydownload iconDownload
public class MyApplication extends Application
{	
	@Override
    public void onCreate()
    {
        super.onCreate();

        OkHttpClient okHttpClient = new OkHttpClient.Builder()
//                .addInterceptor(new LoggerInterceptor("TAG"))
                  .connectTimeout(10000L, TimeUnit.MILLISECONDS)
                  .readTimeout(10000L, TimeUnit.MILLISECONDS)
                  //其他配置
                 .build();
                 
        OkHttpUtils.initClient(okHttpClient);

    }
}

对于Cookie(包含Session)

copy iconCopydownload iconDownload
CookieJarImpl cookieJar = new CookieJarImpl(new PersistentCookieStore(getApplicationContext()));
OkHttpClient okHttpClient = new OkHttpClient.Builder()
          .cookieJar(cookieJar)
          //其他配置
         .build();
                 
OkHttpUtils.initClient(okHttpClient);

对于Log

copy iconCopydownload iconDownload
 OkHttpClient okHttpClient = new OkHttpClient.Builder()
       .addInterceptor(new LoggerInterceptor("TAG"))
        //其他配置
        .build();
OkHttpUtils.initClient(okHttpClient);

对于Https

copy iconCopydownload iconDownload
HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(null, null, null);
OkHttpClient okHttpClient = new OkHttpClient.Builder()
        .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager)
         //其他配置
         .build();
OkHttpUtils.initClient(okHttpClient);

GET请求

copy iconCopydownload iconDownload
String url = "http://www.csdn.net/";
OkHttpUtils
    .get()
    .url(url)
    .addParams("username", "hyman")
    .addParams("password", "123")
    .build()
    .execute(new StringCallback()
	        {
	            @Override
	            public void onError(Request request, Exception e)
	            {
	                
	            }
	
	            @Override
	            public void onResponse(String response)
	            {
	
	            }
	        });

POST请求

copy iconCopydownload iconDownload
 OkHttpUtils
    .post()
    .url(url)
    .addParams("username", "hyman")
    .addParams("password", "123")
    .build()
    .execute(callback);

Post JSON

copy iconCopydownload iconDownload
  OkHttpUtils
    .postString()
    .url(url)
    .content(new Gson().toJson(new User("zhy", "123")))
     .mediaType(MediaType.parse("application/json; charset=utf-8"))
    .build()
    .execute(new MyStringCallback());

Post File

copy iconCopydownload iconDownload
 OkHttpUtils
	.postFile()
	.url(url)
	.file(file)
	.build()
	.execute(new MyStringCallback());

Post表单形式上传文件

copy iconCopydownload iconDownload
OkHttpUtils.post()//
    .addFile("mFile", "messenger_01.png", file)//
    .addFile("mFile", "test1.txt", file2)//
    .url(url)
    .params(params)//
    .headers(headers)//
    .build()//
    .execute(new MyStringCallback());

自定义CallBack

copy iconCopydownload iconDownload
public abstract class UserCallback extends Callback<User>
{
    @Override
    public User parseNetworkResponse(Response response) throws IOException
    {
        String string = response.body().string();
        User user = new Gson().fromJson(string, User.class);
        return user;
    }
}

 OkHttpUtils
    .get()//
    .url(url)//
    .addParams("username", "hyman")//
    .addParams("password", "123")//
    .build()//
    .execute(new UserCallback()
    {
        @Override
        public void onError(Request request, Exception e)
        {
            mTv.setText("onError:" + e.getMessage());
        }

        @Override
        public void onResponse(User response)
        {
            mTv.setText("onResponse:" + response.username);
        }
    });

下载文件

copy iconCopydownload iconDownload
 OkHttpUtils//
	.get()//
	.url(url)//
	.build()//
	.execute(new FileCallBack(Environment.getExternalStorageDirectory().getAbsolutePath(), "gson-2.2.1.jar")//
	{
	    @Override
	    public void inProgress(float progress)
	    {
	        mProgressBar.setProgress((int) (100 * progress));
	    }
	
	    @Override
	    public void onError(Request request, Exception e)
	    {
	        Log.e(TAG, "onError :" + e.getMessage());
	    }
	
	    @Override
	    public void onResponse(File file)
	    {
	        Log.e(TAG, "onResponse :" + file.getAbsolutePath());
	    }
	});

显示图片

copy iconCopydownload iconDownload
 OkHttpUtils
    .get()//
    .url(url)//
    .build()//
    .execute(new BitmapCallback()
    {
        @Override
        public void onError(Request request, Exception e)
        {
            mTv.setText("onError:" + e.getMessage());
        }

        @Override
        public void onResponse(Bitmap bitmap)
        {
            mImageView.setImageBitmap(bitmap);
        }
    });

上传下载的进度显示

copy iconCopydownload iconDownload
new Callback<T>()
{
    //...
    @Override
    public void inProgress(float progress)
    {
       //use progress: 0 ~ 1
    }
}

HEAD、DELETE、PUT、PATCH

copy iconCopydownload iconDownload

OkHttpUtils
     .put()//also can use delete() ,head() , patch()
     .requestBody(RequestBody.create(null, "may be something"))//
     .build()//
     .execute(new MyStringCallback());

同步的请求

copy iconCopydownload iconDownload
 Response response = OkHttpUtils
    .get()//
    .url(url)//
    .tag(this)//
    .build()//
    .execute();

取消单个请求

copy iconCopydownload iconDownload
 RequestCall call = OkHttpUtils.get().url(url).build();
 call.cancel();
 

根据tag取消请求

copy iconCopydownload iconDownload
OkHttpUtils
    .get()//
    .url(url)//
    .tag(this)//
    .build()//

@Override
protected void onDestroy()
{
    super.onDestroy();
    //可以取消同一个tag的
    OkHttpUtils.cancelTag(this);//取消以Activity.this作为tag的请求
}

混淆

copy iconCopydownload iconDownload
#okhttputils
-dontwarn com.zhy.http.**
-keep class com.zhy.http.**{*;}


#okhttp
-dontwarn okhttp3.**
-keep class okhttp3.**{*;}


#okio
-dontwarn okio.**
-keep class okio.**{*;}


Community Discussions

Trending Discussions on okhttputils
  • android java how to protect/ secure my Hardcoded Password
  • How do I ignore Server Certificate with okhttp3?
Trending Discussions on okhttputils

QUESTION

android java how to protect/ secure my Hardcoded Password

Asked 2021-Jul-31 at 19:04

i want to make CertPinning, sending request with clientcertificate. for that i need to put my password hardcoded to use it in the keystore init:

keyManagerFactory.init(keyStore, Password.toCharArray());

how can I protect it?

File pKeyFile;
InputStream caInput = new BufferedInputStream(OkHttpUtils.class.getClassLoader().getResourceAsStream("assets/acptamancli.pfx"));
String Password= "MyPassword!";
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("X509");
KeyStore keyStore = KeyStore.getInstance("PKCS12");
// InputStream keyInput = new FileInputStream(caInput);
keyStore.load(caInput, Password.toCharArray());
caInput.close();
keyManagerFactory.init(keyStore, Password.toCharArray());
SSLContext context = SSLContext.getInstance("TLS");
context.init(keyManagerFactory.getKeyManagers(), null, new SecureRandom());
SSLSocketFactory sockFact = context.getSocketFactory();
con.setSSLSocketFactory(sockFact);
/* Send the request */
OutputStream outputStream = con.getOutputStream();
outputStream.write(requestParams.getBytes("UTF-8"));
outputStream.close();
InputStream inputStream;

if(comparePKeys) {
    // Check for errors
    int responseCode = con.getResponseCode();
    if (responseCode == HttpURLConnection.HTTP_OK) {
        inputStream = con.getInputStream();
    } else {
        inputStream = con.getErrorStream();
    }
} else{
    inputStream = con.getErrorStream();
}

// Process the response
InputStream is = inputStream;
int i;
BufferedReader reader;
String line = null;
reader = new BufferedReader(new InputStreamReader(inputStream));
String result =  reader.readLine();
inputStream.close();
callback.invoke(null, result);
} catch (Exception e) {
    e.printStackTrace();
}

ANSWER

Answered 2021-Jul-31 at 19:02

You don't. Anything present in the distributed package can be accessed by someone who has it.

Note that you're mixing two separate concepts, certificate pinning and client certificates. Client certificates are very rarely used outside an internal corporate environment, and pinned public certificates don't need to be hidden.

Source https://stackoverflow.com/questions/68605018

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install okhttputils

You can download it from GitHub.
You can use okhttputils like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the okhttputils component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Share this Page

share link
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.