Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Sockets and Internet Protocols
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Ron McLeod
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Sockets and Internet Protocols
content-length
Robert Kennedy
Ranch Hand
Posts: 63
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I am trying to determine the content-length for a post.
Is this correct?
private static final String strB= "---------------------------7d22c61f5b8"; private static final String strBLF = "-----------------------------7d22c61f5b8\r\n"; private static final String strBLD = "\r\n-----------------------------7d22c61f5b8\r\n"; StringBuffer sbFileParameters = (new StringBuffer()) .append("Content-Disposition: form-data; name=\""+file.getName()+"\"; filename=\"" + file.getCanonicalPath() + "\"\r\n") .append("Content-Type: image/pjpeg\r\n\r\n"); StringBuffer sbHeaderParameters = (new StringBuffer(strB)) .append(constructParam ("file_sep",File.separator)) .append(constructParam ("userid",strUserId)); StringBuffer sbHttpHeader =(new StringBuffer("POST ")) .append(uUrl.getFile()) .append(" HTTP/1.1\r\n") .append("Content-Type: multipart/form-data, boundary=\"") .append(strB) .append("\"\r\nCache-Control: no-cache\r\n") .append("Pragma: no-cache\r\n") .append("User-Agent: Mozilla/4.0 (Windows XP 5.1) Java/1.5.0_06\r\n") .append("Host: " + uUrl.getHost() + "\r\n") .append("Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\n") .append("Connection: keep-alive\r\n") .append("Content-Length: ") .append(getContentLength(sbFileParameters, sbHeaderParameters)) .append("\r\n"); // write to socket write(sbHttpHeader); write(sbHeaderParameters); write(sbFileParameters); while ( ((bytesReadIn = fis.read(buffer)) != -1) ) write(buffer, 0, bytesReadIn); write(strBLD); ...... private long getContentLength(StringBuffer sbFileParams, StringBuffer sbHeaderParams) { long len=0; len += sbHeaderParams.toString().getBytes().length; len += sbFileParams.toString().getBytes().length; len += file.length(); len +=strBLD.getBytes().length; return len; }
Always! Wait. Never. Shut up. Look at this tiny ad.
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
J2ME HttpConnection problem ...
JPEG Image Upload
Fake a post request from java class
sending image to server using HTTP connection
Rendering dynamic web content
More...