Java 类com.squareup.okhttp.FormEncodingBuilder 实例源码

项目:Library-Token-Automation    文件:LoginActivity.java   
Call post(Callback callback) throws IOException {
    OkHttpClient client = getUnsafeOkHttpClient();
    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    client.setCookieHandler(cookieManager);
    RequestBody requestBody = new FormEncodingBuilder()
            .add("user_id", NetId)
            .add("user_password", password)
            .build();
    Request request = new Request.Builder()
            .url("https://studentmaintenance.webapps.snu.edu.in/students/public/studentslist/studentslist/loginauth")
            .post(requestBody)
            .build();
    Call call = client.newCall(request);
    call.enqueue(callback);
    return call;
}
项目:Android-nRF-Beacon-for-Eddystone    文件:RefreshAccessTokenTask.java   
@Override
protected Void doInBackground(Void... params) {

    RequestBody requestBody = new FormEncodingBuilder()
            .add("refresh_token", mRefreshToken)
            .add("client_id", mClientId)
            .add("client_secret", "ADD_YOUR_CLIENT_SECRET")
            .add("grant_type", "refresh_token")
            .build();
    final Request request = new Request.Builder()
            .url(Utils.ACCESS_TOKEN_URL)
            .post(requestBody)
            .build();
    mOkHttpClient.newCall(request).enqueue(new HttpCallback(mCallBack));
    return null;
}
项目:Android-nRF-Beacon-for-Eddystone    文件:RequestAccessTokenTask.java   
@Override
protected Void doInBackground(Void... params) {

    RequestBody requestBody = new FormEncodingBuilder()
            .add("grant_type", "authorization_code")
            .add("client_id", mClientId)
            .add("client_secret", "ADD_YOUR_CLIENT_SECRET")
            .add("redirect_uri","")
            .add("code", mCode)
            .build();
    final Request request = new Request.Builder()
            .url(url)
            .post(requestBody)
            .build();
    mOkHttpClient.newCall(request).enqueue(new HttpCallback(mCallBack));
    return null;
}
项目:ktball    文件:OkHttpPostRequest.java   
@Override
protected RequestBody buildRequestBody()
{
    RequestBody requestBody = null;
    switch (type)
    {
        case TYPE_PARAMS:
            FormEncodingBuilder builder = new FormEncodingBuilder();
            addParams(builder, params);
            requestBody = builder.build();
            break;
        case TYPE_BYTES:
            requestBody = RequestBody.create(MEDIA_TYPE_STREAM, bytes);
            break;
        case TYPE_FILE:
            requestBody = RequestBody.create(MEDIA_TYPE_STREAM, file);
            break;
        case TYPE_STRING:
            requestBody = RequestBody.create(MEDIA_TYPE_STRING, content);
            break;
    }
    return requestBody;
}
项目:ktball    文件:OkHttpPostRequest.java   
private void addParams(FormEncodingBuilder builder, Map<String, String> params)
{
    if (builder == null)
    {
        throw new IllegalArgumentException("builder can not be null .");
    }

    if (params != null && !params.isEmpty())
    {
        for (String key : params.keySet())
        {
            builder.add(key, params.get(key));
            LogUtils.e(key+":"+params.get(key));
        }
    }
}
项目:okhttp-oauth    文件:OkHttpOAuthClient.java   
@Override
public Call newRequestToken(String callback) {
    Request req = new Request.Builder()
            .url(provider.requestTokenUrl())
            .method(provider.requestTokenVerb(), new FormEncodingBuilder().build())
            .header("X-OKHttp-OAuth-Authorized", "yes")
            .build();

    OAuthRequest orq = new OAuthRequest(req);
    try {
        OAuthRequest authReq = service.authorizeRequest(orq, consumer, null);

        return okHttpClient.newCall(authReq.authorizedRequest());
    } catch (SigningException e) {
        e.printStackTrace(); // TODO what to do now?!?
    }

    return null;
}
项目:okhttp-oauth    文件:OkHttpOAuthClient.java   
@Override
public Call newAccessToken(String verifier) {
    Request req = new Request.Builder()
            .url(provider.requestTokenUrl())
            .method(
                    provider.requestTokenVerb(),
                    new FormEncodingBuilder()
                    .add(OAuth.VERIFIER, verifier)
                    .build()
                )
            .build();

    OAuthRequest orq = new OAuthRequest(req);
    try {
        OAuthRequest authReq = service.authorizeRequest(orq, consumer, null);

        return okHttpClient.newCall(authReq.authorizedRequest());
    } catch (SigningException e) {
        e.printStackTrace(); // TODO what to do now?!?
    }

    return null;
}
项目:meishiDemo    文件:OkHttpPostRequest.java   
@Override
protected RequestBody buildRequestBody()
{
    validParams();
    RequestBody requestBody = null;


    switch (type)
    {
        case TYPE_PARAMS:
            FormEncodingBuilder builder = new FormEncodingBuilder();
            addParams(builder, params);
            requestBody = builder.build();
            break;
        case TYPE_BYTES:
            requestBody = RequestBody.create(mediaType != null ? mediaType : MEDIA_TYPE_STREAM, bytes);
            break;
        case TYPE_FILE:
            requestBody = RequestBody.create(mediaType != null ? mediaType : MEDIA_TYPE_STREAM, file);
            break;
        case TYPE_STRING:
            requestBody = RequestBody.create(mediaType != null ? mediaType : MEDIA_TYPE_STRING, content);
            break;
    }
    return requestBody;
}
项目:Angular2-OnlineCinema    文件:AccountController.java   
@Path("notification/subscribe")
@POST
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public String subscribe(@FormParam(value = "token") String token) throws IOException {
    String url = "https://iid.googleapis.com/iid/v1/" + token + "/rel/topics/" + TOPIC_NAME;

    OkHttpClient client = new OkHttpClient();
    RequestBody body = new FormEncodingBuilder()
               .build();
    Request request = new Request.Builder()
      .url(url)
      .addHeader("Content-Type", "application/json")
      .addHeader("Authorization", AUTHEN)
      .post(body)
      .build();

    Response response = client.newCall(request).execute();


    return String.valueOf(response.code());
}
项目:Angular2-OnlineCinema    文件:BHDParser.java   
@Override
 public void parse() throws IOException {
    Document doc = Jsoup.connect("http://bhdstar.vn/lich-chieu-theo-phim/").get();      
    Elements elements = doc.select("ul[class=slides bhd-lich-chieu-chon-phim]").get(0).children();

    for (int i = 0; i < elements.size(); i++) {
        Film film = FilmManager.searchFilmByName(elements.get(i).select("span[class=movie--name]").text());
        if (film == null)
            continue;
    OkHttpClient client = new OkHttpClient();
    RequestBody body = new FormEncodingBuilder()
              .add("action", "bhd_lichchieu_chonphim")
              .add("movies_id", elements.get(i).select("a").attr("data-id"))
              .build();
    Request request = new Request.Builder()
     .url(ajaxUrl)
     .post(body)
     .build();

Response response = client.newCall(request).execute();
addShowTimes(response.body().string(), film);


    }
 }
项目:MousePaintYzz    文件:BaseHttp.java   
protected void basePost(String url, Map<String, String> params, CallbackListener<T> listener)
{
    if (params == null) {
       baseGet(url,listener);return;
    }
    FormEncodingBuilder builder = new FormEncodingBuilder();
    Set<Map.Entry<String, String>> entrySet = params.entrySet();
    for (Map.Entry<String, String> entry : entrySet) {
        builder.add(entry.getKey(), entry.getValue());
    }
    RequestBody requestBody = builder.build();
    Request request = new Request.Builder()
            .url(url)
            .post(requestBody)
            .tag(url)
            .build();
    doRequest(request, listener);
}
项目:AndroidGeek    文件:OkHttpClientManager.java   
private Request buildPostFormRequest(String url, Param[] params, Object tag) {
    if (params == null) {
        params = new Param[0];
    }
    FormEncodingBuilder builder = new FormEncodingBuilder();
    for (Param param : params) {
        builder.add(param.key, param.value);
    }
    RequestBody requestBody = builder.build();


    Request.Builder reqBuilder = new Request.Builder();
    reqBuilder.url(url)
            .post(requestBody);

    if (tag != null) {
        reqBuilder.tag(tag);
    }
    return reqBuilder.build();
}
项目:okhttp-oauth    文件:OkHttpOAuthClient.java   
@Override
public Call newRequestToken(String callback) {
    Request req = new Request.Builder()
            .url(provider.requestTokenUrl())
            .method(provider.requestTokenVerb(), new FormEncodingBuilder().build())
            .header("X-OKHttp-OAuth-Authorized", "yes")
            .build();

    OAuthRequest orq = new OAuthRequest(req);
    try {
        OAuthRequest authReq = service.authorizeRequest(orq, consumer, null);

        return okHttpClient.newCall(authReq.authorizedRequest());
    } catch (SigningException e) {
        e.printStackTrace(); // TODO what to do now?!?
    }

    return null;
}
项目:okhttp-oauth    文件:OkHttpOAuthClient.java   
@Override
public Call newAccessToken(String verifier) {
    Request req = new Request.Builder()
            .url(provider.requestTokenUrl())
            .method(
                    provider.requestTokenVerb(),
                    new FormEncodingBuilder()
                    .add(OAuth.VERIFIER, verifier)
                    .build()
                )
            .build();

    OAuthRequest orq = new OAuthRequest(req);
    try {
        OAuthRequest authReq = service.authorizeRequest(orq, consumer, null);

        return okHttpClient.newCall(authReq.authorizedRequest());
    } catch (SigningException e) {
        e.printStackTrace(); // TODO what to do now?!?
    }

    return null;
}
项目:Android-BluetoothSPPLibrary-master    文件:MainHistory.java   
public void insertTOserver(final String dt, final String tt, final String ds, final String ts){
    try {
        final String SITE_URL = "http://168.63.175.28/addHistory.php";

        TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        RequestBody formBody = new FormEncodingBuilder()
                .add("isAdd", "true")
                .add("imei", telephonyManager.getDeviceId())
                .add("datestart", dt)
                .add("timestart", tt)
                .add("datestop", ds)
                .add("timestop", ts)
                .build();

        PostForm p= new PostForm(formBody,SITE_URL);
        final Toast toast = Toast.makeText(getApplicationContext(), "เก็บประวัติแล้ว", Toast.LENGTH_SHORT);
        toast.show();
    }
    catch (Exception ex){
        Log.v("ex", ex.toString());
    }
}
项目:Android-BluetoothSPPLibrary-master    文件:RSSPullService.java   
public void insertTOserverLocation(final String dt, final Double lati, final Double longti){
    try {
        Log.v("insertTOserverLocation", lati + " " + longti);
        TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        final String SITE_URL = "http://168.63.175.28/addLocation.php";

        RequestBody formBody = new FormEncodingBuilder()
                .add("isAdd", "true")
                .add("imei", telephonyManager.getDeviceId())
                .add("time", dt)
                .add("la", Double.toString(lati))
                .add("lo", Double.toString(longti))
                .build();

        PostForm p= new PostForm(formBody,SITE_URL);
        final Toast toast = Toast.makeText(getApplicationContext(), "เก็บตำแหน่งปัจจุบันแล้ว", Toast.LENGTH_SHORT);
        toast.show();
    }
    catch (Exception ex){
        Log.v("ex",ex.toString());
    }
}
项目:Android-BluetoothSPPLibrary-master    文件:RSSPullService.java   
public void insertTOserverTemp(final String dt,final double temp1, final double temp2){
        try{
            Log.v("insertTOserverTemp",temp1+" / "+temp2);
            final String SITE_URL = "http://168.63.175.28/addDATA.php";

            TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
            RequestBody formBody = new FormEncodingBuilder()
                    .add("isAdd", "true")
                    .add("imei", telephonyManager.getDeviceId())
                    .add("time", dt)
                    .add("node1", String.valueOf(temp1))
                    .add("node2", String.valueOf(temp2))
                    .build();

            PostForm p= new PostForm(formBody,SITE_URL);
            final Toast toast = Toast.makeText(getApplicationContext(), "เก็บค่าอุณหภูมิแล้ว", Toast.LENGTH_SHORT);
//            toast.show();
        }
        catch (Exception ex){
            Log.v("ex",ex.toString());
        }
    }
项目:android-kit-old    文件:OkHttpPostRequest.java   
@Override
protected RequestBody buildRequestBody() {
    validParams();
    RequestBody requestBody = null;


    switch (type) {
        case TYPE_PARAMS:
            FormEncodingBuilder builder = new FormEncodingBuilder();
            addParams(builder, params);
            requestBody = builder.build();
            break;
        case TYPE_BYTES:
            requestBody = RequestBody.create(mediaType != null ? mediaType : MEDIA_TYPE_STREAM, bytes);
            break;
        case TYPE_FILE:
            requestBody = RequestBody.create(mediaType != null ? mediaType : MEDIA_TYPE_STREAM, file);
            break;
        case TYPE_STRING:
            requestBody = RequestBody.create(mediaType != null ? mediaType : MEDIA_TYPE_STRING, content);
            break;
    }
    return requestBody;
}
项目:csapp    文件:Delete.java   
/**
 * 删除某个文章
 * @param uid uid
 * @param cookie cookie
 * @return the result of delete
 * @throws IOException
 */
public static String deleteArticle(String uid,String cookie) throws IOException {

    OkHttpClient client = new OkHttpClient();
    RequestBody formBody = new FormEncodingBuilder()
            .add("uid",uid)
            .build();

    Request request = new Request.Builder()
            .url("http://128.199.101.105:8080/articles/")
            .delete(formBody)
            .addHeader("cookie", cookie)
            .build();

    Response response = client.newCall(request).execute();
    if (!response.isSuccessful()) Log.i("Delete Error", "Delete Failed");
    return response.body().string();
}
项目:csapp    文件:Delete.java   
/**
 * 取消赞或收藏
 * @param act 进行的操作 1是取消收藏 2是取消赞
 * @param uid the uid
 * @param cookie the cookie
 * @return the result of delete
 * @throws IOException
 */
public static String deleteZanorCollect(int act,String uid,String cookie) throws IOException {

    OkHttpClient client = new OkHttpClient();
    RequestBody formBody = new FormEncodingBuilder()
            .add("act",act+"")
            .build();

    Request request = new Request.Builder()
            .url("http://128.199.101.105:8080/articles/detail/"+uid+"/")
            .delete(formBody)
            .addHeader("cookie", cookie)
            .build();

    Response response = client.newCall(request).execute();
    if (!response.isSuccessful()) Log.i("Delete Error", "Delete Failed");
    return response.body().string();
}
项目:csapp    文件:Delete.java   
public static String deleteComment(String uid,String cookie) throws IOException {

        OkHttpClient client = new OkHttpClient();
        RequestBody formBody = new FormEncodingBuilder()
                .add("uid",uid)
                .build();

        Request request = new Request.Builder()
                .url("http://128.199.101.105:8080/articles/")
                .delete(formBody)
                .addHeader("cookie", cookie)
                .build();

        Response response = client.newCall(request).execute();
        if (!response.isSuccessful()) Log.i("Delete Error", "Delete Failed");
        return response.body().string();
    }
项目:csapp    文件:PostJson.java   
/**
 *post失物招领
 * @param url url
 * @param lostandfound the lostandfound instance
 * @return the result of post
 * @throws IOException
 */
public static String postLostandfound(String url, LostAndFound lostandfound) throws IOException {

    RequestBody formBody = new FormEncodingBuilder()
            .add("title", lostandfound.getTitle())
            .add("message",lostandfound.getMessage())
            .add("content",lostandfound.getContent())
            .build();


    OkHttpClient client = new OkHttpClient();
    Request request = new Request.Builder()
            .url(url)
            .post(formBody)
            .build();
    Response response = client.newCall(request).execute();
    if (!response.isSuccessful()) Log.i("Post Error","Post Failed");
    return response.body().string();
}
项目:csapp    文件:PostJson.java   
/**
 *用于用户注册
 * @param user the User instance
 * @return the result of post
 * @throws IOException
 */
public static String postUsers(User user)throws  IOException{

    RequestBody formBody = new FormEncodingBuilder()
            .add("username",user.getUsername())
            .add("password", user.getPassword())
            .add("email",user.getEmail())
            .add("confirm",user.getConfirm())
            .build();

    OkHttpClient client = new OkHttpClient();

    Request request = new Request.Builder()
            .url("http://128.199.101.105:8080/users/")
            .post(formBody)
            .build();

    Response response = client.newCall(request).execute();
    if (!response.isSuccessful()) Log.i("Post Error","Post Failed");
    return response.body().string();
}
项目:csapp    文件:PostJson.java   
/**
 * 用来登录
 * @param user the User instance
 * @return the result of post
 * @throws IOException
 */
public static String userLogin(User user)throws  IOException{

    RequestBody formBody = new FormEncodingBuilder()
            .add("username", user.getUsername())
            .add("password", user.getPassword())
            .build();

    OkHttpClient client = new OkHttpClient();

    Request request = new Request.Builder()
            .url("http://128.199.101.105:8080/entry/")
            .post(formBody)
            .build();

    Response response = client.newCall(request).execute();
    if (!response.isSuccessful()) Log.i("Post Error","Post Failed");
    Log.i("userLogin response",response.body().string());
    return response.header("Set-Cookie", "null");
}
项目:csapp    文件:PostJson.java   
/**
 * 发表文章
 * @param article the Article  Instance
 * @param cookie cookie
 * @return the result of post
 * @throws IOException
 */
public static String postArticle(Article article,String cookie) throws  IOException{
    RequestBody formBody = new FormEncodingBuilder()
            .add("title",article.getTitle())
            .add("content", article.getContent())
            .build();

    OkHttpClient client = new OkHttpClient();

    Request request = new Request.Builder()
            .url("http://128.199.101.105:8080/articles/")
            .post(formBody)
            .addHeader("cookie", cookie)
            .build();

    Response response = client.newCall(request).execute();
    if (!response.isSuccessful()) Log.i("Post Error","Post Failed");
    return response.body().string();
}
项目:csapp    文件:PostJson.java   
/**
 * 进行关注
 * @param uid the uid
 * @param cookie the cookie
 * @return
 * @throws IOException
 */
public static String postFollower(String uid,String cookie) throws  IOException{


    OkHttpClient client = new OkHttpClient();

    RequestBody formBody = new FormEncodingBuilder()
            .add("","")
            .build();

    Request request = new Request.Builder()
            .url("http://128.199.101.105:8080/users/detail/"+uid+"/")
            .post(formBody)
            .addHeader("cookie", cookie)
            .build();

    Response response = client.newCall(request).execute();
    if (!response.isSuccessful()) Log.i("Post Error","Post Failed");
    return response.body().string();
}
项目:csapp    文件:PostJson.java   
/**
 * 操作(赞或者收藏)某个个文章
 * @param act 操作码 1代表收藏2代表点赞1=>collect,2=>zan
 * @param uid the uid
 * @param cookie the cookie
 * @return the result of post
 * @throws IOException
 */
public static String postZanorCollect(int act,String uid,String cookie) throws  IOException{


    OkHttpClient client = new OkHttpClient();

    RequestBody formBody = new FormEncodingBuilder()
            .add("act",act+"")
            .build();

    Request request = new Request.Builder()
            .url("http://128.199.101.105:8080/articles/detail/"+uid+"/")
            .post(formBody)
            .addHeader("cookie", cookie)
            .build();

    Response response = client.newCall(request).execute();
    if (!response.isSuccessful()) Log.i("Post Error","Post Failed");
    return response.body().string();
}
项目:csapp    文件:PostJson.java   
/**
 * 提交评论
 * @param content the content
 * @param uid the uid
 * @param cookie the cookie
 * @return the result of post
 * @throws IOException
 */
public static String postComment(String content,String uid,String cookie) throws  IOException{


    OkHttpClient client = new OkHttpClient();

    RequestBody formBody = new FormEncodingBuilder()
            .add("content",content)
            .build();

    Request request = new Request.Builder()
            .url("http://128.199.101.105:8080/comments/"+uid+"/")
            .post(formBody)
            .addHeader("cookie", cookie)
            .build();

    Response response = client.newCall(request).execute();
    if (!response.isSuccessful()) Log.i("Post Error","Post Failed");
    return response.body().string();
}
项目:snu-data-usage    文件:MainActivity.java   
/**
 * Send POST request to the server to log the user in or out.
 *
 * @param mode  Mode is used by the server script to differentiate between login and logout.
 *              191: Login
 *              193: Logout
 * @param username The username of user
 * @param password The password of user
 * @param callback The Callback
 * @return Call object
 * @throws IOException
 */
Call post(String mode, String username, String password, Callback callback) throws IOException {
    OkHttpClient client = new OkHttpClient();
    RequestBody formBody = new FormEncodingBuilder()
            .add("mode", mode)
            .add("username", username + "@snu.in")
            .add("password", password)
            .build();
    Request request = new Request.Builder()
            .url("http://192.168.50.1/24online/servlet/E24onlineHTTPClient")
            .post(formBody)
            .build();
    Call call = client.newCall(request);
    call.enqueue(callback);
    return call;
}
项目:snu-data-usage    文件:LoginActivity.java   
Call post(Callback callback) throws IOException {
    OkHttpClient client = getUnsafeOkHttpClient();
    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    client.setCookieHandler(cookieManager);
    RequestBody requestBody = new FormEncodingBuilder()
            .add("user_id", NetId)
            .add("user_password", password)
            .build();
    Request request = new Request.Builder()
            .url("https://studentmaintenance.webapps.snu.edu.in/students/public/studentslist/studentslist/loginauth")
            .post(requestBody)
            .build();
    Call call = client.newCall(request);
    call.enqueue(callback);
    return call;
}
项目:MousePaint    文件:BaseHttp.java   
protected void basePost(String url, Map<String, String> params, CallbackListener<T> listener)
{
    if (params == null) {
       baseGet(url,listener);return;
    }
    FormEncodingBuilder builder = new FormEncodingBuilder();
    Set<Map.Entry<String, String>> entrySet = params.entrySet();
    for (Map.Entry<String, String> entry : entrySet) {
        builder.add(entry.getKey(), entry.getValue());
    }
    RequestBody requestBody = builder.build();
    Request request = new Request.Builder()
            .url(url)
            .post(requestBody)
            .tag(url)
            .build();
    doRequest(request, listener);
}
项目:meiShi    文件:OkHttpPostRequest.java   
@Override
protected RequestBody buildRequestBody()
{
    validParams();
    RequestBody requestBody = null;


    switch (type)
    {
        case TYPE_PARAMS:
            FormEncodingBuilder builder = new FormEncodingBuilder();
            addParams(builder, params);
            requestBody = builder.build();
            break;
        case TYPE_BYTES:
            requestBody = RequestBody.create(mediaType != null ? mediaType : MEDIA_TYPE_STREAM, bytes);
            break;
        case TYPE_FILE:
            requestBody = RequestBody.create(mediaType != null ? mediaType : MEDIA_TYPE_STREAM, file);
            break;
        case TYPE_STRING:
            requestBody = RequestBody.create(mediaType != null ? mediaType : MEDIA_TYPE_STRING, content);
            break;
    }
    return requestBody;
}
项目:Bugtags-Android    文件:Okhttp2Test.java   
public static void postUrlencode() {
    String urlStr = HOST_PREFIX + "/post/encode?xxx=bb";

    RequestBody body = new FormEncodingBuilder().
            add("name", "hello").
            add("p1", "1").
            add("p2", "2").
            build();

    Request request = new Request.Builder().
            url(urlStr).post(body).
            addHeader("a", "b").
            addHeader("b", "c").
            build();

    try {
        Response response = okHttpClient.newCall(request).execute();
        Log.d(TAG, response.body().string());

    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:okhttp-utils    文件:OkHttpPostRequest.java   
@Override
protected RequestBody buildRequestBody()
{
    validParams();
    RequestBody requestBody = null;


    switch (type)
    {
        case TYPE_PARAMS:
            FormEncodingBuilder builder = new FormEncodingBuilder();
            addParams(builder, params);
            requestBody = builder.build();
            break;
        case TYPE_BYTES:
            requestBody = RequestBody.create(mediaType != null ? mediaType : MEDIA_TYPE_STREAM, bytes);
            break;
        case TYPE_FILE:
            requestBody = RequestBody.create(mediaType != null ? mediaType : MEDIA_TYPE_STREAM, file);
            break;
        case TYPE_STRING:
            requestBody = RequestBody.create(mediaType != null ? mediaType : MEDIA_TYPE_STRING, content);
            break;
    }
    return requestBody;
}
项目:Qianlichuanyin    文件:RegisterActivity.java   
@OnClick(R.id.btn_register_submit)
void register() {
    showProgressDialog("正在注册,请稍后...");
    String mobile = etMobile.getText().toString();
    String nickname = etNickname.getText().toString();
    if (!StringUtils.isPhone(mobile)) {
        UIHelper.showToast("请输入正确的手机号~");
        return;
    }
    if (!StringUtils.isNick(nickname)) {
        UIHelper.showToast("请输入昵称(不能是中文)~");
        return;
    }
    FormEncodingBuilder builder = new FormEncodingBuilder();
    builder.add("phone", mobile);
    builder.add("nickname", nickname);
    TaskQueue.getDefault().addSerially(getCallable(AppConfig.REGISTER_URL, builder), callback, this);
}
项目:JianDan_OkHttp    文件:OkHttpProxy.java   
public static Call post(String url, Map<String, String> params, Object tag, OkHttpCallback responseCallback) {

        Request.Builder builder = new Request.Builder().url(url);
        if (tag != null) {
            builder.tag(tag);
        }

        FormEncodingBuilder encodingBuilder = new FormEncodingBuilder();

        if (params != null && params.size() > 0) {
            for (String key : params.keySet()) {
                encodingBuilder.add(key, params.get(key));
            }
        }

        RequestBody formBody = encodingBuilder.build();
        builder.post(formBody);

        Request request = builder.build();
        Call call = getInstance().newCall(request);
        call.enqueue(responseCallback);
        return call;
    }
项目:runtasticapi    文件:RequestHandler.java   
private boolean login(String user, String password) {
    RequestBody body = new FormEncodingBuilder().add("user[email]", user)
            .add("user[password]", password).build();
    Request request = new Request.Builder().url(URLs.loginUrl).post(body)
            .build();
    Response response = run(request);
    String resp = null;
    if (response.code() != 200)
        return false;
    try {
        resp = response.body().string();
    } catch (IOException e) {
        return false;
    }
    JsonObject json = new JsonParser().parse(resp).getAsJsonObject();
    Document document = Jsoup.parse(json.get("update").getAsString());
    String token = document.select("input[name=authenticity_token]").val();
    String userName = document
            .select("a[href~=https://www.runtastic.com/en/users/(.*)/dashboard]")
            .attr("href").split("/")[5];

    this.session = new Session(token, userName);
    return true;
}
项目:Logistics-guard    文件:OkHttpClientManager.java   
private Request buildPostRequest(String url, Param[] params) {
    if (params == null) {
        params = new Param[0];
    }
    FormEncodingBuilder builder = new FormEncodingBuilder();
    for (Param param : params) {
        builder.add(param.key, param.value);
    }
    RequestBody requestBody = builder.build();
    return new Request.Builder()
            .url(url)
            .post(requestBody)
            .build();
}
项目:afp-api-client    文件:ApiClient.java   
/**
 * Build a form-encoding request body with the given form parameters.
 *
 * @param formParams Form parameters in the form of Map
 * @return RequestBody
 */
public RequestBody buildRequestBodyFormEncoding(Map<String, Object> formParams) {
    FormEncodingBuilder formBuilder  = new FormEncodingBuilder();
    for (Entry<String, Object> param : formParams.entrySet()) {
        formBuilder.add(param.getKey(), parameterToString(param.getValue()));
    }
    return formBuilder.build();
}