Commit d7ba076a authored by yanzg's avatar yanzg

修改保存历史记录

parent 3b142e18
......@@ -37,6 +37,21 @@ public class HttpCodeException extends RuntimeException {
return target;
}
/**
* 构造函数
* throw new CodeException("01","该订单已过期",order);
* throw new CodeException("02","该订单未到使用时间",order);
*
* @param code  错误码
* @param message  错误消息
*/
public HttpCodeException(String code, String message) {
super(message);
this.code = code;
this.target = null;
}
/**
* 构造函数
* throw new CodeException("01","该订单已过期",order);
......
......@@ -184,7 +184,14 @@ public class HttpHelper {
// flush输出流的缓冲
out.flush();
in = readStream(httpConn.getInputStream(), result, charset);
int returnCode = httpConn.getResponseCode();
if (returnCode == HttpURLConnection.HTTP_OK) {
in = readStream(httpConn.getInputStream(), result, charset);
} else {
throw new HttpCodeException(StringHelper.toString(returnCode), httpConn.getResponseMessage());
}
} catch (HttpCodeException ex) {
throw ex;
} catch (Exception ex) {
in = readStream(httpConn.getErrorStream(), result, charset);
throw new HttpCodeException(StringHelper.toString(httpConn.getResponseCode()), ex.getMessage(), result.toString(), ex);
......
......@@ -54,4 +54,12 @@ public class HttpHelperTest {
BaiduHelper.BaiduDate result = BaiduHelper.getBaiduData(new Date());
System.out.println(result.getStatus());
}
@Test
public void testRequest() {
String url = "http://39f55e6bb381.ngrok.io/reserveInfo/addSgReserveInfo.do";
String post = "{\"appointmentDate\":\"2021-07-27\",\"arriveAddress\":\"40288ae86ccd4bc8016ccd4c84cf0001\",\"arriveTime\":\"0\",\"cardType\":\"二代身份证\",\"openid\":\"TBD\",\"visitorCardId\":\"43052419871104817X\",\"visitorName\":\"燕子\",\"visitorPhone\":\"13800138000\"}";
String result = HttpHelper.post(url, post);
System.out.println(result);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment