httppost添加cookie

httppost添加cookie,第1张

httppost添加cookie的方法具体如下:

第一种

HashMap map = new HashMap()

map.put("cookie","p1u_id=4eb591e73554db0f4d3300cb656113abfb968ef6b0ee2b5de0a35caa5217c51faa028b453576b35c")

networkConnection.setHeaderList(map)

NetworkConnection.ConnectionResult result = networkConnection.execute()

第二种是用okhttp

OkHttpClient client = new OkHttpClient()

String returnData=null

com.squareup.okhttp.Request request = new com.squareup.okhttp.Request.Builder()

addHeader("cookie", "p1u_id=4eb591e73554db0f4d3300cb656113abfb968ef6b0ee2b5de0a35caa5217c51faa028b453576b35c")

url(url)

.build()

Response response = null

try {

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

returnData=response.body().string()

Log.i("ss", "url is " + url + "_______RETUNRN DATA IS " + returnData)

} catch (IOException e) {

e.printStackTrace()

}

$time = gmstrftime("%A, %d-%b-%Y %H:%M:%S GMT", time()+10)

header("Set-Cookie: cookiename=cookieValue expires={$time}")

格式搞错了。 通过header方法设置过期时间是这种格式的。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11185685.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-14
下一篇 2023-05-14

发表评论

登录后才能评论

评论列表(0条)

保存