Home > Back-end >  The HTTP request error
The HTTP request error

Time:09-18

Public static JSONObject postFormUrlEecoded (RestTemplate RestTemplate, url String, the String body) {
System. The out. Println (" postFormUrlEecoded url="+ url);
System. The out. Println (" postFormUrlEecoded body="+ body);

Return request (restTemplate, url, MediaType. APPLICATION_FORM_URLENCODED HttpMethod. POST, the body, "");
}

Public static JSONObject request (RestTemplate RestTemplate, String url, MediaType MediaType, HttpMethod HttpMethod, String body, the Object... UriVariables) {
HttpHeaders HttpHeaders=new HttpHeaders ();
HttpHeaders. SetContentType (mediaType);

HttpEntity MapHttpEntity=new HttpEntity<> (body, httpHeaders);
ResponseEntity ResponseEntity=null;
Try {
Logger. The info (" {} {} request parameters, url, body);
ResponseEntity=restTemplate. Exchange (url, httpMethod, mapHttpEntity, String class, uriVariables);
} the catch (RestClientException e) {
e.printStackTrace();
return null;
}
If (responseEntity getStatusCodeValue ()==200) {
Logger. The info (" {} {} "request results, url, responseEntity. GetBody ());
Return a JSON. ParseObject (responseEntity getBody ());
} else {
Logger. Error (request {} "failure", url);
return null;
}
}

Org. Springframework. Web. Client. RestClientException: Error while extracting the response for the type [class Java. Lang. String] and the content type (application/json; charset=utf-8 16]. Nested exception is org. Springframework. HTTP. Converter. HttpMessageNotReadableException: JSON parse error: always deserialize the instance of ` Java lang. String ` out of START_OBJECT token; Nested exception is com. Fasterxml. Jackson. Databind. Exc. MismatchedInputException: always deserialize the instance of ` Java lang. String ` out of START_OBJECT token
At [Source: (PushbackInputStream); the line: 1, the column: 1)
The at org. Springframework. Web. Client. HttpMessageConverterExtractor. ExtractData (HttpMessageConverterExtractor. Java: 117)
The at org. Springframework. Web. Client. $ResponseEntityResponseExtractor RestTemplate. ExtractData (RestTemplate. Java: 995)
The at org. Springframework. Web. Client. $ResponseEntityResponseExtractor RestTemplate. ExtractData (RestTemplate. Java: 978)
The at org. Springframework. Web. Client. RestTemplate. The doExecute (RestTemplate. Java: 737)
The at org. Springframework. Web. Client. RestTemplate. Execute (RestTemplate. Java: 670)
At org. Springframework. Web. Client. RestTemplate. Exchange (579) RestTemplate. Java:
At com. Butech. Bmcporabvsrv. Util. RestTemplateUtil. Request (55) RestTemplateUtil. Java:
At com. Butech. Bmcporabvsrv. Util. RestTemplateUtil. PostFormUrlEecoded (RestTemplateUtil. Java: 22)
At com. Butech. Bmcporabvsrv. Support. Erp. ErpOpenApi. Login (ErpOpenApi. Java: 56)

CodePudding user response:

Check START_OBJECT's object is to realize the serial interface

CodePudding user response:

//set to receive the return value format for json
List MediaTypeList=new ArrayList<> (a);
MediaTypeList. Add (mediaType);
HttpHeaders. SetAccept (mediaTypeList);

CodePudding user response:

Json parsing errors, interface the data returned is not standard json format

CodePudding user response:

Request header application/json means the foreground to background passing json data

CodePudding user response:

The body format is wrong
  • Related