Android sslpeerunverifiedexception no peer certificate, JSON SSL -
Android sslpeerunverifiedexception no peer certificate, JSON SSL -
i read lot of topics on web , on stack overflow.. still cannot code working right.. still getting: android sslpeerunverifiedexception no peer certificate
this code, , if can help me grateful:
public class mainactivity extends activity { arraylist<string> namearraylist = new arraylist<string>(); arraylist<string> countryarraylist = new arraylist<string>(); string graveurl = "https://example.com/grave.json"; protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); new json().execute(); } class json extends asynctask<void, void, string> { protected void onpreexecute() { super.onpreexecute(); } protected string doinbackground(void... params) { httpclient httpclient = createhttpclient(); httppost httppost = new httppost(graveurl); seek { httpresponse response = httpclient.execute(httppost); statusline statusline = response.getstatusline(); int statuscode = statusline.getstatuscode(); if (statuscode != 200) { homecoming null; } inputstream jsonstream = response.getentity().getcontent(); bufferedreader reader = new bufferedreader( new inputstreamreader(jsonstream)); stringbuilder builder = new stringbuilder(); string line; while ((line = reader.readline()) != null) { builder.append(line); } string jsondata = builder.tostring(); jsonobject json = new jsonobject(jsondata); jsonarray name = json.getjsonarray("graves"); (int = 0; < name.length(); i++) { jsonobject video = name.getjsonobject(i); namearraylist.add(video.getstring("id_line")); countryarraylist.add(video.getstring("id_grave")); } } grab (clientprotocolexception e) { e.printstacktrace(); } grab (ioexception e) { e.printstacktrace(); } grab (jsonexception e) { e.printstacktrace(); } homecoming null; } protected void onpostexecute(string result) { super.onpostexecute(result); toast.maketext(getapplicationcontext(), "hello" + namearraylist.get(0).tostring(), toast.length_long).show(); } } public static httpclient createhttpclient() { httpparams params = new basichttpparams(); httpprotocolparams.setversion(params, httpversion.http_1_1); httpprotocolparams.setcontentcharset(params, http.default_content_charset); httpprotocolparams.setuseexpectcontinue(params, true); schemeregistry schreg = new schemeregistry(); schreg.register(new scheme("http", plainsocketfactory .getsocketfactory(), 80)); schreg.register(new scheme("https", sslsocketfactory.getsocketfactory(), 443)); clientconnectionmanager conmgr = new threadsafeclientconnmanager( params, schreg); homecoming new defaulthttpclient(conmgr, params); } }
mostly of code got on stack overflow looks cannot set pieces works correctly..
thx in advance
this server uses untrusted certificate, hence exception. can bypass creating own ssl socket factory, or adding certificate on device.
android json ssl
Comments
Post a Comment