java - 500 Internal error from HTTP POST request -


i using below code upload file using http post, getting 500 internal server error response server.

can please have , let me know code part culprit/missing. there no error in https connection, think problem in header server not accepting request.

    // check server address     url = new url("https://example.com");     string protocol = url.getprotocol();      string host = url.gethost();     string serviceroot = url.getpath();      // build post request     httppost post = new httppost(new uri(protocol + "://" + host             + serviceroot));     post.addheader("user-agent", "test");     post.addheader("content-type", "multipart/form-data");      post.addheader("accept", "image/jpg");      string authvalue = "basic "             + base64                     .encodebase64tostring(("username" + ":"                             + "password").getbytes()) + " " + "realm=\"example.com\"";     if (authvalue != null) {         post.addheader("authorization", authvalue);     }      file file = new file("/sdcard/download/imag0306.jpg");     filebody data = new filebody(file);      string file_type = "jpg" ;     string description = "test";      multipartentity reqentity = new multipartentity();     reqentity.addpart("file_name", new stringbody( file.getname() ) );     reqentity.addpart("description", new stringbody(description));     reqentity.addpart("file_type", new stringbody(file_type));     reqentity.addpart("data", data);      post.setentity(reqentity);       if (true) {         string trace = ">>> send http request:";         trace += "\n " + post.getmethod() + " "                 + post.getrequestline().geturi();         system.out.println(trace);     }      if (true) {         string trace = "<<< send http request-->:";         trace += "\n" + post.tostring();         header[] headers = post.getallheaders();         (header header : headers) {             trace += "\n" + header.getname() + " " + header.getvalue();         }         system.out.println(trace);     }      httpclient httpclient = createhttpclient();     // replace url     // “authorization”, “basic ” + encodedusernamepassword);     if (httpclient != null) {         response = httpclient.execute(post);         if (true) {             string trace = "<<< receive http response:";             trace += "\n" + response.getstatusline().tostring();             header[] headers = response.getallheaders();             (header header : headers) {                 trace += "\n" + header.getname() + " " + header.getvalue();             }             system.out.println(trace);         }     } else {         throw new ioexception("http client not found");     } 

thanks

500 internal server error server error, ie. problem on server side, not client side. need check server logs see problem is.

the headers fine. if headers wrong, 400 bad request or other 4xx error instead.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -