java 如何使用 URLConnection 添加会话 ID
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14979288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to add session id using URLConnection
提问by Rasmikanta Guru
I am trying to upload an image to a server using server url. For this i am using java.net
api.
After sending request , it is returning a response that shows session invalid.
I am getting the session id from that server but unable to add it.
How can i add session id using HttpURLConnection
while sending request to server.
Is their any way to solve this?
我正在尝试使用服务器 url 将图像上传到服务器。为此,我正在使用java.net
api。发送请求后,它返回一个显示会话无效的响应。我正在从该服务器获取会话 ID,但无法添加它。如何HttpURLConnection
在向服务器发送请求时添加会话 ID 。他们有什么办法解决这个问题吗?
回答by Oleg Mikheev
Session ID is stored in a cookie, in JavaEE its name is jsessionid
, and you add it like that:
会话 ID 存储在 cookie 中,在 JavaEE 中它的名称是jsessionid
,您可以像这样添加它:
httpURLConnection.setRequestProperty(
"Cookie","JSESSIONID=" + your_session_id);