Java HttpURLConnection - POST with Cookie

前端 未结 1 1715
梦如初夏
梦如初夏 2021-02-14 06:50

I´m trying to send a post request with cookies. This is the code:

try {

    String query = URLEncoder.encode(\"key\", \"UTF-8\") + \"=\" + URLEncoder.encode(\"v         


        
相关标签:
1条回答
  • 2021-02-14 07:26

    According to the URLConnection javadoc:

    The following methods are used to access the header fields and the 
    contents AFTER the connection is made to the remote object:
    
    * getContent
    * getHeaderField
    * getInputStream
    * getOutputStream
    

    Have you confirmed that in your test case above the request is getting to the server at all? I see you have the call to connect() after getOutputStream() and commented-out besides. What happens if you uncomment it and move up before the call to getOutputStream() ?

    0 讨论(0)
提交回复
热议问题