本文整理汇总了Java中com.squareup.okhttp.mockwebserver.MockResponse.addHeader方法的典型用法代码示例。如果您正苦于以下问题:Java MockResponse.addHeader方法的具体用法?Java MockResponse.addHeader怎么用?Java MockResponse.addHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.okhttp.mockwebserver.MockResponse
的用法示例。
在下文中一共展示了MockResponse.addHeader方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import com.squareup.okhttp.mockwebserver.MockResponse; //导入方法依赖的package包/类
@Override
public MockResponse handle(RecordedRequest request, String root) {
String path = request.getPath();
RequestInfo requestInfo = new RequestInfo();
int index = path.indexOf("?");
if (index > -1) {
String queryString = path.substring(index + 1);
path = path.substring(0, index);
requestInfo.params = HttpUtil.getParamsMap(queryString, Util.UTF_8.name());
}
if(path.startsWith("/download/")){
MockResponse mr = handleDownload(request, root);
mr.addHeader("RequestHeaders",request.getHeaders().toString());
mr.addHeader("RequestParams",requestInfo.params);
return mr;
}
requestInfo.method = request.getMethod();
requestInfo.path = path;
requestInfo.headers = request.getHeaders().toMultimap();
String methodUp = requestInfo.method.toUpperCase();
if(methodUp.equals("POST")||methodUp.equals("PUT")){
requestInfo.bodyInfo = createBodyInfo(request);
}
BaseResult<RequestInfo> result = new BaseResult<>();
result.requestMethod = requestInfo.method;
result.requestPath = requestInfo.path;
result.data = requestInfo;
return new MockResponse().setStatus("HTTP/1.1 200").addHeader("content-type: application/json; charset=utf-8")
.setBody(JSON.toJSONString(result));
}