java - Android HttpURLConnection POST Request with image/jpeg -


i trying send image in post request httpurlconnection. have next code:

string i3 = string.valueof(system.currenttimemillis()); bytearrayoutputstream i4 = new bytearrayoutputstream(); i4.write(("--" + i3 + system.lineseparator()         + "content-disposition: form-data; name=\"" + i1.this.i2 + "\"; filename=\"" + i1.this.i2 + ".jpg\"" + system.lineseparator()         + "content-type: image/jpeg" + system.lineseparator()         + "content-length: " + string.valueof(i2.this.i1.length) + system.lineseparator() + system.lineseparator()).getbytes()); i4.flush(); i4.write(i2.this.i1); i4.flush(); i4.write((system.lineseparator() + system.lineseparator() + "--" + i3 + "--").getbytes()); i4.flush(); i4.close(); httpurlconnection i5 = (httpurlconnection) new url(myurl).openconnection(); i5.setrequestmethod("post"); i5.setdooutput(true); i5.setrequestproperty("user-agent", "mozilla/5.0"); i5.setrequestproperty("content-type", "multipart/form-data; boundary=" + i3); i5.setfixedlengthstreamingmode(i4.tobytearray().length); i5.connect(); outputstream i6 = i5.getoutputstream(); i6.write(i4.tobytearray()); i6.flush(); i6.close(); system.out.println(i5.getresponsecode() + " " + i5.getresponsemessage()); i5.disconnect(); 

but when i'm trying response code/message of connection application throws me exception:

07-28 12:15:00.722: java.io.ioexception: unexpected end of stream on connection{123.456.789.012:80, proxy=direct@ hostaddress=123.456.789.012 ciphersuite=none protocol=http/1.1} (recycle count=0)

maybe problem post request bad or having syntax errors? can me , what's wrong, please.


i tested code on java application on windows! result of request 200 ok. conclusion: wrong android! still don't know concretically.

i found solution! ugly strings system.lineseparator() need replaced old kind \r\n! great.


Comments

Popular posts from this blog

Combining PHP Registration and Login into one class with multiple functions in one PHP file -

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -