0

I need to upload a file to server. If i use the "curl -i -F filedata=@"PATH TO FILE" http://█.199.166.14/audiostream " it return a 200 OK code (Or may be this command incorrect) . But when I use java function

public String send()
{
    try {
        url = "http://█.199.166.14/audiostream";
        File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "test.pcm");
        try {
            Log.d("transmission", "started");
            HttpClient httpclient = new DefaultHttpClient();

            HttpPost httppost = new HttpPost(url);
            ResponseHandler Rh = new BasicResponseHandler();

            InputStreamEntity reqEntity = new InputStreamEntity(new FileInputStream(file), -1);
            reqEntity.setContentType("binary/octet-stream");
            reqEntity.setChunked(true); // Send in multiple parts if needed
            httppost.setEntity(reqEntity);
            HttpResponse response = httpclient.execute(httppost);

            response.getEntity().getContentLength();
            StringBuilder sb = new StringBuilder();
            try {
                BufferedReader reader =
                        new BufferedReader(new InputStreamReader(response.getEntity().getContent()), 65728);
                String line = null;

                while ((line = reader.readLine()) != null) {
                    sb.append(line);
                }
            }
            catch (IOException e) { e.printStackTrace(); }
            catch (Exception e) { e.printStackTrace(); }


            Log.d("Response", sb.toString());
            Log.d("Response", "StatusLine : " + response.getStatusLine() + " Entity: " + response.getEntity()+ " Locate: " + response.getLocale() + " " + Rh);
            return sb.toString();
        } catch (Exception e) {
            // show error
            Log.d ("Error", e.toString());
            return e.toString();
        }
    }
    catch (Exception e)
    {
        Log.d ("Error", e.toString());
        return e.toString();
    }

}

It's return 400 Bad request. I'm also not sure that server proceed correctly my attempts to upload this file, but I can't check it.

1 Answers1

0

From the error received its likely a bad formatted HTTP query. If audiostream is a php, write the full link.

Also it seems that there might be a wrong/bad encoded char at "http://█.199.166.14/audiostream, the link should be http://(IP or DNS)/(rest of URL)(the URI)

You should erase the link, then manually writte it again.

If those didnt fix the issue, its also possible that the Server (or its path equipment) might be blocking you. Check from the Access Log and the security rules of its accesses, that you are not blocked (some routers may block users from performing repeated querys as a sort of anti "Denial of Service" measure)

Bonatti
  • 2,778
  • 5
  • 23
  • 42