第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

volley JsonObjectRequest post請(qǐng)求

標(biāo)簽:
Android

注意:使用JsonObjectRequest或继承自JsonObjectRequest类的对象提交一个post请求时,如果有参数需要提交,就必须以JSONObject的json串方式提交.否则通过重写getParams()方法的方式提交不管用,getParams()方法中提交post参数只适用于Request对象。

直接上代码:第一部分是调用,第二部分是自定义

JsonObjectRequestWithCookie

private void uploadUserOp(String opType, String musicKey) throws AuthFailureError {
        Log.w("LOG","invoke uploadUserOp with "+ opType+" and "+musicKey);
        HashMap<String, String> opMap = new HashMap<String, String>();
        opMap.put("op", opType);
        opMap.put("key", musicKey);
        JSONObject opJsonObject = new JSONObject(opMap);
        JsonObjectRequestWithCookie jsonObjectRequestWithCookie = new JsonObjectRequestWithCookie(Constants.USER_HISTORY_URL,opJsonObject, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                Log.w("LOG","get response jsonObject from post user history"+jsonObject.toString());
                try {
                    if(jsonObject.getString("status").equals("success")){
                        Log.w("LOG", "post /api/use/history/ success");
                    }
                    else{
                        Log.w("LOG", "post /api/use/history/ failure");
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                Log.w("LOG", "操作失败");
            }
        },opMap);
        jsonObjectRequestWithCookie.setCookie(localCookie);
        RequestManager.getRequestQueue().add(jsonObjectRequestWithCookie);
    }
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.toolbox.JsonObjectRequest;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by lsc on 2014/12/24.
 */
public class JsonObjectRequestWithCookie extends JsonObjectRequest {
    private Map<String, String> mHeaders = new HashMap<>();
    public JsonObjectRequestWithCookie(String url, JSONObject jsonRequest, Response.Listener<JSONObject> listener, Response.ErrorListener errorListener,Map<String,String> map) {
        super(Request.Method.POST, url, jsonRequest, listener, errorListener);

    }
    public JsonObjectRequestWithCookie(String url, JSONObject jsonRequest, Response.Listener<JSONObject> listener, Response.ErrorListener errorListener){
        super(url, jsonRequest, listener, errorListener);
    }

    //拿到客户端发起的http请求的Header
    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
        return mHeaders;
    }

    //发送请求时,往Header中添加cookie,可以一并发送
    public void setCookie(String cookie) throws AuthFailureError {
        mHeaders.put("User-Agent", "Android:1.0:2009chenqc@163.com");
        mHeaders.put("Cookie",cookie);
    }
}

更多类型的post解释,可参见:http://www.open-open.com/lib/view/open1407727047207.html

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺(jué)得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消