0
http를 통해 JSONObject를 통해 메시지를 보내려고합니다.json, 응답 코드 500에 슬래시 문자를 다시 보냅니다.
JSONObject s=new JSONObject();
s.put("addresses", sno);
s.put("message",message);
s.put("senderName",shortcode);
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write(s.toJSONString());
wr.flush();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
메시지는 같은 :
String message= “amount1\\KB \n amount2\\KB”
예상 수신 한 메시지 :
amount1\KB
amount2\KB
이제 문제는 HTTP 서버가 온라인 9 주에서 나를 reponse 코드 (500) 그리고 원인 예외 반환합니다 : 문제 영역은 문자열 부분 \ KB입니다. 문자열에이 백 슬래시가 포함되지 않으면 모든 것이 잘됩니다. 내 모든 예외를 발생하지 않는
message = message.replaceAll("\\\\", "\");
message = message.replaceAll("\\\\", "%5C");
하지만, 수신 된 메시지는 다음과 같은했다 :
나는 시도했다
amount1\KB
amount2\KB
및
amount1%5CKB
amount2%5CKB
JSONObject.escape(message)
코드 스 니펫에 기본 제공 서식을 사용할 수 있습니다. –
its : message = message.replaceAll ("\\\\", "\\"); message = message.replaceAll ("\\\\", "% 5C"); –