zoukankan      html  css  js  c++  java
  • OKhttp初步

    OkHttp

    使用方法:
    1.分为同步和异步。
    同步:
    1.get
    Request request = new Request.Builder().url(utl).build();
    Response respone = client.newCall(request).execute();
    if(respone.isSuccessful()){
    retrurn respone.body().string();
    }
    else {
    throw new IOExceptrion(""+respone);
    }

    1.Request 是请求。 Reponse是响应。

    Post提交键值对
    RequestBody body=new FormEncodeingBuilder().add("name","value").add
    ("name1","value1").build();

    Request request =new Request.Builder().url(url).post(body).build();

    同步步骤:
    RequestBody(可选)
    Request
    Response
    client.newCall(request).execute();

    异步:
    client.newCall(request).enqueue(new CallBack(){
    @override
    public void onFailure(Request request,IOException e){

    }
    @override
    public void onResponse (final Request respone)throws IOException{

    }
    });

  • 相关阅读:
    java线程管理
    java进程间通信
    Possible multiple enumeration of IEnumerable
    Adding Search
    Working with SQL Server LocalDB
    ASP.NET Razor
    ASP.NET Razor
    modelstate.isvalid false
    Razor Intro
    open Command window here
  • 原文地址:https://www.cnblogs.com/lzh-Linux/p/4974040.html
Copyright © 2011-2022 走看看