Cannot write URLConnection because of doOutput

后端 未结 3 1821
独厮守ぢ
独厮守ぢ 2021-02-20 07:11

I\'ve asked a question here and I\'ve fixed my problem thanks to an user. This is the code I am using at the moment.

void UploadToDatabase() throws MalformedURLE         


        
3条回答
  •  悲&欢浪女
    2021-02-20 07:48

    The problem lies on this line:

    WritableByteChannel rbc = Channels.newChannel(website.openConnection().getOutputStream());
    

    You will need to set doOutput to true for this to work. Here's how:

    URLConnection urlc = website.openConnection();
    urlc.setDoOutput(true);
    WritableByteChannel rbc = Channels.newChannel(urlc.getOutputStream());
    

提交回复
热议问题