java - Can't conenct to a url -
i have link i'm providing 2 parameters , php server side script executing query , writing them databae.
the problem in specific case, seems can't connect teh url.
here button xml file:
<button android:layout_width="match_parent" android:layout_height="wrap_content" android:includefontpadding="@+id/btnsubmit" android:text="@string/btnsubmit" android:onclick="submitnewj" />
here click "listener":
public void submitnewj(view view){ new submitj().execute(); }
and here submitj
code:
public class submitj extends asynctask<void, integer, void>{ @override protected void doinbackground(void... params) { try{ string encodedname = urlencoder.encode(name,"utf-8"); string encodedbody = urlencoder.encode(body,"utf-8"); url url = new url("http://site123.com/android/j/sj.php?name="+encodedname+"&body="+encodedbody); urlconnection urlconnection = url.openconnection(); @suppresswarnings("unused") inputstream in = urlconnection.getinputstream(); }catch(exception e){ e.printstacktrace(); } return null; } }
and here how i'm getting strings:
edittext jn; edittext jb; string name = ""; string body = ""; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_new_joke); jn = (edittext)findviewbyid(r.id.newname); jb = (edittext)findviewbyid(r.id.newbody); name = jn.gettext().tostring(); body = jb.gettext().tostring(); }
it seems connection not working here(even when i'm using same code in otehr activities). mistaking? know i'm missing super small, i'm not able spot it.
p.s. service , link 100% tested , working.
the site have in example probabbly reference reasons, mind if using https
protocol , you're reffering http
, not redirected correct link. in code seems fine me. make sure you're using correct protocol.
Comments
Post a Comment