在调用Rest API时,出现错误“对等重置连接”。
我尝试了此链接,但对我而言不起作用。我认为这是连接超时问题,但仍无法解决。 javax.net.ssl.SSLException: Read error: ssl=0x9524b800: I/O error during system call, Connection reset by peer
private class HttpLogin extends AsyncTask<String, String, ResponseEntity<Login_List_model>> {
private ProgressDialog progress = new ProgressDialog(Login.this);
@Override
protected ResponseEntity<Login_List_model> doInBackground(String... strings) {
try {
String orgname_ = orgname.toString();
String url = "https://dev.azure.com/"+orgname_ +"/_apis/projects?api-version=5.0" ;
HttpHeaders headers = createHttpHeaders(user,token_);
HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
ResponseEntity<Login_List_model> response = restTemplate.exchange(url, HttpMethod.GET, entity, Login_List_model.class);
//After this step , moves to catch giving error msg : Connection reset by peer.
return response;
} catch (Exception e) {
this.progress.setMessage(""); // Error
}
return null;
}
@Override
protected void onPreExecute() {
// getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.progress.setMessage("Loading Results");
this.progress.show();
}
ViewPager viewPager;
@Override
protected void onPostExecute(final ResponseEntity<Login_List_model> result) {
super.onPostExecute(result);
if (progress.isShowing()) {
progress.dismiss();
}
String resul = result.getBody().getValues().toString();
tv_rs.setText(resul);
}
}
private HttpHeaders createHttpHeaders(String user, String password)
{
String notEncoded = user + ":" + password;
byte[] encrpt= new byte[0];
try {
encrpt = notEncoded.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String base64 = Base64.encodeToString(encrpt, Base64.DEFAULT).toString();
String text_ = base64.replace("\n","");
String encodedAuth = "Basic " + text_;
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("Authorization", encodedAuth);
return headers;
}
现在得到空结果。我需要Json回应作为结果。