How to send a cookie in a URLConnection?

后端 未结 2 902
醉梦人生
醉梦人生 2021-01-02 03:21

What is the proper way to send a \'full\' cookie across a URLConnection?

I\'ve been using:

URL url = new URL(page);  
URLConnection urlConn = url.op         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-02 04:12

    Well, if you are only setting a cookie I guess you could simply do like:

    urlConn.setRequestProperty("Cookie", "user=mary17; domain=airtravelbargains.com; path=/autos");
    

    If you're setting more than one cookie than you could probably use the addRequestProperty method instead.

    For the expires attribute make sure to use the format: Weekday, DD-Mon-YY HH:MM:SS GMT.

    The only legal time zone is GMT, and the separators between the elements of the date must be dashes.

提交回复
热议问题