Results 1 to 3 of 3
  1. #1
    Boomn4x4 is offline Member
    Join Date
    Nov 2011
    Posts
    18
    Rep Power
    0

    Default Content-Dispostion Error

    I'm having trouble sending an http request to a web service that contains a file's data. The web service expects the files binary stream as "blob" field. When I'm sending the request, I'm getting a HTTP Status 400 - java.lang.RuntimeException: Could find no Content-Disposition header within part. I don't understand why.

    Java Code:
    byte[] fileData = new byte[(int) file.length()];
    	    FileInputStream bfis = new FileInputStream(file);
    	    bfis.read(fileData);
    	    bfis.close();
    	    String blob = "";
    	    for(byte b: fileData){
    	    	blob += getBits(b);
    	    }
    	    String basestring = server + "/v1/" + reqId;
    	 //   String test = base64.toString();
    		URL obj2 = new URL(basestring + "/operations");
    		HttpURLConnection con2 = (HttpURLConnection) obj2.openConnection();
    		con2.setRequestMethod("POST");
    		con2.setRequestProperty("Content-Type", "multipart/form-data;boundary=DkdHd939dDDksl333Dkad");
    		con2.setRequestProperty("Content-Disposition", "form-data; name=\"" + file.getName() + "\"; filename=\"" + file.getName() + "\"");
    		con2.setRequestProperty("Accept-Encoding", "multipart/form-data");
    		con2.setRequestProperty("blob", blob);
    		con2.setRequestProperty("filename", file.getName());
    		con2.setRequestProperty("checksum", checksum);
    		con2.setRequestProperty("accept", "application/json");
    		con2.setDoInput(true);
    		con2.setDoOutput(true);
    		
    		
    		rc = con2.getResponseCode();
    		System.out.println("Ops Reply Code: " + rc);
    		
    		if (rc >= 400){
    			in = new BufferedReader(new InputStreamReader(con2.getErrorStream()));
    		}
    		else{
    			in = new BufferedReader(new InputStreamReader(con2.getInputStream()));
    		}
    		
    		inLine = new String();
    		resp = new StringBuffer();
    		while ((inLine = in.readLine()) != null ){
    			resp.append(inLine);
    		}

    Any help would be appreciated.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Content-Dispostion Error

    Is this an HTTP user problem?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Content-Dispostion Error

    The 400 HTTP code seems to be a custom response from the web service, you'll have to ask the people maintaining it what's wrong with your request format, or check any documentation that I hope is available.

    That being said: you set doOutput() to true yet your code does not call conn2.getOutputStream() and write a request body. What happens when you set doOutput to false?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. getting error content disposition in browser
    By amarjitsrm in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 09-11-2012, 10:39 AM
  2. Replies: 1
    Last Post: 04-19-2011, 08:52 AM
  3. Replies: 2
    Last Post: 05-30-2009, 10:42 AM
  4. Replies: 1
    Last Post: 07-24-2007, 01:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •