我正在尝试通过base64编码的字符串将文件字节从客户端发送到控制器。 我能够发送较小尺寸的普通字符串。但是当我尝试发送长字符串(基本64位二进制编码)时,在服务器端获取null。请指导我。 我的服务器端和客户端代码在
下面在客户端
try{
byte[] getBytes = Files.readAllBytes(Paths.get("C:/Sample/123.csv"));
byte[] enc = Base64.encodeBase64(getBytes);
String encodedString = new String(enc);
String urlParameters = "param1="+encodedString+"¶m2=virendra";
byte[] postData = urlParameters.getBytes( StandardCharsets.UTF_8 );
int postDataLength = postData.length;
System.out.println(postDataLength);
String request = "http://localhost:9090//getSingerDetails";
URL url = new URL( request );
HttpURLConnection conn= (HttpURLConnection) url.openConnection();
conn.setDoOutput( true );
conn.setInstanceFollowRedirects( false );
conn.setRequestMethod( "POST" );
conn.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty( "charset", "utf-8");
conn.setRequestProperty( "Content-Length", Integer.toString( postDataLength ));
conn.setUseCaches( false );
try( DataOutputStream wr = new DataOutputStream( conn.getOutputStream())) {
wr.write( postData );
}
System.out.println("Response Code FOR bulkDataUpload : "+conn.getResponseCode());
}
catch(Exception e){
e.printStackTrace();
}
AT服务器端代码
@RequestMapping(value = "/getSingerDetails", method = RequestMethod.POST)
public @ResponseBody JsonResponse seeding2BackendTrans (Map<String, String> map, HttpSession session,
@RequestParam Map<String,Object> param ) throws IOException {
System.out.println("param1-->"+String.valueOf(param.get("param1")));
System.out.println("param2-->"+String.valueOf(param.get("param2")));
我正在获得param1的值,而param2是null。 但是当我传递statice值的encodedString时。我得出正确的说法。 请帮忙。
由于