请求标题登录webapp后如下
Accept application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Cache-Control no-cache
Connection keep-alive
Content-Length 5195
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Cookie JSESSIONID=DC83EEF14C3B1F309ADF125B92A62629; _ga=GA1.2.1119685758.1496394454; _gid=GA1.2.682909819.1496644441
Host gpsdevci.pdx.aws
Pragma no-cache
Referer http://sample URL
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0
X-CSRF-Token a92b8e7c-8f50-4d64-8290-58409b481109
X-CSRF-Uri /cgw/cases/listAsJSON
X-Requested-With XMLHttpRequest
我使用的代码如下
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost request = new HttpPost("https://gpsdevci.pdx.aws/cgw-api/v2.0.0/case");
StringEntity params = new StringEntity("{\"panelName\":\"comprehensive_cancer_panel_version_3\",\"sampleType\":\"patientcare\",\"indication\":\"Identified Indication\",\"disease\":{\"code\":\"254837009\",\"label\":\"Malignant tumor of breast\"},\"physicians\":[{\"firstName\":\"fName\",\"lastName\":\"lName\"}],\"identified\":true,\"specimens\":[{\"name\":\"primarySpecimen\",\"type\":{\"code\":\"441652008\",\"label\":\"Formalin-fixed paraffin-embedded tissue specimen\"},\"accessionNumber\":\"abc\",\"dateAccessioned\":\"2016-03-29T20:00:00Z\",\"datecollected\":\"2016-03-29T20:00:00Z\",\"dateReceived\":\"2016-03-29T20:00:00Z\",\"dateOfBirth\":\"2001-10-12\",\"firstName\":\"fname\",\"lastName\":\"Lname\",\"medicalRecordNumbers\":[{\"medicalFacility\":{\"hospitalNumber\": \"1\",\"facility\": \"TEST facility\"},\"mrn\":\"MRN1\"}],\"clientName\":\"GPS\"}]}");
request.addHeader("Accept", "application/json, text/javascript, */*; q=0.01");
//request.addHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
request.addHeader("Authorization", HeaderOAuth);
request.addHeader("Content-type","application/json; charset=UTF-8");
request.addHeader("Accept","application/json; charset=UTF-8");
request.addHeader("Accept-Encoding","gzip, deflate");
request.addHeader("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0");
request.addHeader("Accept-Language","en-US,en;q=0.5");
request.addHeader("Cookie","JSESSIONID=DC83EEF14C3B1F309ADF125B92A62629; _ga=GA1.2.1119685758.1496394454; _gid=GA1.2.682909819.1496644441");
request.addHeader("Connection", "keep-alive");
request.addHeader("X-CSRF-Token", "5ba25ce0-b5b5-40aa-b38d-44234237e7fb");
request.addHeader("Access-Control-Allow-Origin", "*");
request.addHeader("Access-Control-Allow-Methods", "*");
request.addHeader("Access-Control-Allow-Headers", "*");
request.addHeader("Cache-Control", "no-cache");
request.setEntity(params);
HttpResponse response = httpClient.execute(request);
执行代码低于响应后
response: HttpResponseProxy{HTTP/1.1 400 Bad Request [Date: Fri, 09 Jun 2017 11:17:21 GMT, Access-Control-Allow-Origin: *, Set-Cookie: JSESSIONID=9FF5F2DD2BAEC9248B0C2A04A58BCC57; Path=/cgw-api/; Secure; HttpOnly, Cache-Control: no-cache, no-store, max-age=0, must-revalidate, Pragma: no-cache, Expires: 0, Strict-Transport-Security: max-age=31536000 ; includeSubDomains, X-XSS-Protection: 1; mode=block, X-Frame-Options: DENY, X-Content-Type-Options: nosniff, Content-Type: application/json;charset=UTF-8, Connection: close, Transfer-Encoding: chunked] ResponseEntityProxy{[Content-Type: application/json;charset=UTF-8,Chunked: true]}}
请提供建议我尝试了所有的事情
答案 0 :(得分:0)
这不是一个答案,但我还不能发表评论。
我猜你通过在网络浏览器上手动请求服务器得到了标题,并且刚刚捕获了网络内容(Mozilla上的F12)。
所以,我认为你的问题可能是由于X-CSRF-Token值。尝试获取其他标题以获取第一个标头,并查看X-CSRF-Token值是否与之前相同。
X-CSRF-Token是一个安全令牌,它每次都在不断变化。点击此处:wikipedia page