java 接收raw,Java raw 请求和获取

请求类型为raw,请求格式为json;

java发送raw请求代码如下:/*** java发送raw

*@authorzengwei

* @email 15797630391@163.com

*@version2019年3月01日 下午4:02:02*/

public staticJSONObject deviceRequest() {

JSONObject result= null;try{

String url= "url 地址";

JSONObject json= newJSONObject();

json.put("param", param 参数 );

@SuppressWarnings({"resource"})

HttpClient httpClient= newDefaultHttpClient();

HttpPost post= newHttpPost(url);

StringEntity postingString= newStringEntity(json.toJSONString());

post.setEntity(postingString);

post.setHeader("Content-type", "application/json");

HttpResponse response=httpClient.execute(post);

String content=EntityUtils.toString(response.getEntity());

result=(JSONObject) JSONObject.parse(content);

System.out.println(result);

}catch (ParseException |IOException e) {

e.printStackTrace();

}returnresult;

}123456789101112131415161718192021222324252627282930313233java获取raw包请求需要从流中获取:/*** java获取raw

*@authorzengwei

* @email 15797630391@163.com

*@version2019年3月01日 下午4:10:04*/

public staticString readRaw(InputStream inputStream) {

String result= "";try{

ByteArrayOutputStream outSteam= newByteArrayOutputStream();byte[] buffer = new byte[1024];intlen;while ((len = inputStream.read(buffer)) != -1) {

outSteam.write(buffer,0, len);

}

outSteam.close();

inputStream.close();

result= new String(outSteam.toByteArray(), "UTF-8");

}catch(IOException e) {

e.printStackTrace();

}returnresult;

}1234567891011121314151617181920212223242526272829传入参数 使用 request.getInputStream():/*** 广告推广API

*@authorzengwei

* @email 15797630391@163.com

*@version2019年3月01日 下午4:20:05*/String result=FileUtils.readRaw(request.getInputStream());1234