email - Always receive org.apache.http.NoHttpResponseException: The target server failed to respond Android -
i working on http post in android. here code:
sendmail sending = (sendmail) new sendmail() .execute(url + "/mob/android/dummy.php"); public class sendmail extends asynctask<string, string, string> { private string endresult; @override protected string doinbackground(string... val) { string url = val[0]; log.i("url", url + ""); httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost(url); try { cookiestore cookiestore = new basiccookiestore(); ((abstracthttpclient) httpclient).setcookiestore(cookiestore); list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(); namevaluepairs.add(new basicnamevaluepair("name", post_name)); namevaluepairs namevaluepairs.add(new basicnamevaluepair("email", post_email)); namevaluepairs.add(new basicnamevaluepair("message", "requesting appointment from: " + selecteddr + " message: " + post_message)); log.i("namevaluepairs:", "" + namevaluepairs); httppost.setentity(new urlencodedformentity(namevaluepairs)); httpresponse response = httpclient.execute(httppost); basicresponsehandler myhandler = new basicresponsehandler(); endresult = myhandler.handleresponse(response); log.i("namevaluepairs", "" + namevaluepairs); log.i("endresult", "" + endresult); } catch (clientprotocolexception e) { } catch (ioexception e) { } return null; } @override protected void onpostexecute(string result) { super.onpostexecute(result); publishprogress(endresult); } @override protected void onprogressupdate(string... values) { super.onprogressupdate(values); string result = values[0]; t_warning.settext("mail sent."); et_email.settext(""); et_name.settext(""); et_message.settext(""); } }
now till
namevaluepairs.add(new basicnamevaluepair("message", "requesting appointment from: " + selecteddr + " message: " + post_message));
it working fine on httpresponse response = httpclient.execute(httppost); gives no reponse after 3 minutes gives mail sent on mail server received no mail , show exception:
org.apache.http.nohttpresponseexception: target server failed respond
i stuck not understand why happening added permissions
logcat:
04-05 10:41:57.110: i/exception(3926): org.apache.http.nohttpresponseexception: target server failed respond 04-05 10:41:57.110: i/endresult(3926): null
edited code gives logcat:
04-05 10:51:17.160: w/system.err(4016): org.apache.http.nohttpresponseexception: target server failed respond 04-05 10:51:17.170: w/system.err(4016): @ org.apache.http.impl.conn.defaultresponseparser.parsehead(defaultresponseparser.java:85) 04-05 10:51:17.170: w/system.err(4016): @ org.apache.http.impl.io.abstractmessageparser.parse(abstractmessageparser.java:174) 04-05 10:51:17.170: w/system.err(4016): @ org.apache.http.impl.abstracthttpclientconnection.receiveresponseheader(abstracthttpclientconnection.java:180) 04-05 10:51:17.170: w/system.err(4016): @ org.apache.http.impl.conn.defaultclientconnection.receiveresponseheader(defaultclientconnection.java:235) 04-05 10:51:17.170: w/system.err(4016): @ org.apache.http.impl.conn.abstractclientconnadapter.receiveresponseheader(abstractclientconnadapter.java:259) 04-05 10:51:17.170: w/system.err(4016): @ org.apache.http.protocol.httprequestexecutor.doreceiveresponse(httprequestexecutor.java:279) 04-05 10:51:17.170: w/system.err(4016): @ org.apache.http.protocol.httprequestexecutor.execute(httprequestexecutor.java:121) 04-05 10:51:17.170: w/system.err(4016): @ org.apache.http.impl.client.defaultrequestdirector.execute(defaultrequestdirector.java:428) 04-05 10:51:17.170: w/system.err(4016): @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:555) 04-05 10:51:17.170: w/system.err(4016): @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:653) 04-05 10:51:17.170: w/system.err(4016): @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:627) 04-05 10:51:17.170: w/system.err(4016): @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:616) 04-05 10:51:17.170: w/system.err(4016): @ com.ilmasoft.alina_dental.mailus$sendmail.doinbackground(mailus.java:492) 04-05 10:51:17.180: w/system.err(4016): @ com.ilmasoft.alina_dental.mailus$sendmail.doinbackground(mailus.java:1) 04-05 10:51:17.180: w/system.err(4016): @ android.os.asynctask$2.call(asynctask.java:252) 04-05 10:51:17.180: w/system.err(4016): @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:305) 04-05 10:51:17.180: w/system.err(4016): @ java.util.concurrent.futuretask.run(futuretask.java:137) 04-05 10:51:17.180: w/system.err(4016): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1081) 04-05 10:51:17.180: w/system.err(4016): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:574) 04-05 10:51:17.180: w/system.err(4016): @ java.lang.thread.run(thread.java:1020)
try code within doinbackground
list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(); namevaluepairs.add(new basicnamevaluepair("name", post_name)); namevaluepairs.add(new basicnamevaluepair("email", post_email)); namevaluepairs.add(new basicnamevaluepair("message", "requesting appointment from: " + selecteddr + " message: " + post_message)); defaulthttpclient hc = new defaulthttpclient(); responsehandler<string> res = new basicresponsehandler(); httppost postmethod = new httppost(url); string response = null; try { postmethod.setentity(new urlencodedformentity(namevaluepairs)); } catch (unsupportedencodingexception e) { // todo auto-generated catch block e.printstacktrace(); } try { response = hc.execute(postmethod, res); } catch (clientprotocolexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); }
Comments
Post a Comment