JMeter中JSR223 Sampler发送POST请求出现Precondition Failed错误
问题背景
这是我之前两个问题的延续,因目标不同单独开帖。感谢@Dmitri的快速解答。修复所有代码后,我遇到了**Precondition Failed(412前置条件失败)**错误,查看错误信息后,我猜测主要原因是content-type设置问题。
错误详情
HttpResponseProxy{HTTP/1.1 412 Precondition Failed [Date: Thu, 01 Sep 2022 13:39:18 GMT, Content-Type: application/json, Transfer-Encoding: chunked, Connection: keep-alive, Server: openresty, Access-Control-Allow-Origin: *, Access-Control-Expose-Headers: Date, Access-Control-Allow-Headers: X-Acc-Cached,X-File-Name,X-File-Size,X-Requested-With,X-DicomGrid-Client,X-AmbraHealth-part-checksum,X-DicomGrid-Version,X-AmbraHealth-SID,Cache-Control,Content-Encoding,Content-Type,If-None-Match, Access-Control-Request-Headers: X-DicomGrid-Client,X-DicomGrid-Version, Access-Control-Allow-Methods: DELETE,GET,OPTIONS,POST,PATCH,PUT, Vary: Accept-Encoding, Cache-Control: max-age=0, no-cache, Expires: Thu, 01 Sep 2022 13:39:23 GMT] ResponseEntityProxy{[Content-Type: application/json,Chunked: true]}}
代码基础
import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.HttpMultipartMode; import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.impl.client.HttpClientBuilder; def imageFileName = "C:\\Users\\IMAGES\\IMG00001.dcm" def urlRequest='https://'+${BASE_URL_1}+'/api/v3/storage/namespace/7c762733-009f-4527-81ea-571d1cf6e9d2/image?sid='+vars.get('SIDVALUE')+'&study_uid=1.2.300.0.7230010.3.1.2.2595064201.8112.1216202112026121&image_uid=1.2.840.113704.7.1.0.1356918323635126.1521373008.110' def postRequest = new HttpPost(urlRequest); def file = new File(imageFileName); def builder = MultipartEntityBuilder.create(); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); builder.addBinaryBody("file", file, ContentType.DEFAULT_BINARY, imageFileName); def entity = builder.build(); postRequest.setEntity(entity); def response = HttpClientBuilder.create().build().execute(postRequest);
疑问
我是否需要添加content-type:application/dicom请求头?我已经在Header Manager中设置过该请求头了。

内容的提问来源于stack exchange,提问作者Jyoti Prakash Mallick
相关产品推荐
相关产品推荐

