0
請求頭部登錄到web應用程序之後是如下我使用獲取HttpResponseProxy {HTTP/1.1 400錯誤的請求響應
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]}}
請提供建議我試過所有東西
是的你是正確的@Asew,X-CSRF-令牌每次都在不斷變化,但是如果我從代碼中刪除它,那麼我也會得到400個不好的請求。如果是的話,X-CSRF-Token必須添加標題,那麼如何獲取每次新標記請給出解決方案 – sufiya
您是否有權訪問代碼中網頁的源代碼? – Asew
我會檢查並通知你 – sufiya