c# - Error sending a webRequest -


i error when trying send webrequest in xamarin ios.

i want log onto website, works in c# visual studio windows client, ios gives me error.

unhandled exception: monotouch.uikit.uikitthreadaccessexception: uikit consistency error: calling uikit method can invoked ui thread.   @ monotouch.uikit.uiapplication.ensureuithread () [0x00019] in /developer/monotouch/source/monotouch/src/uikit/uiapplication.cs:49    @ monotouch.uikit.uitextfield.get_text () [0x00000] in /developer/monotouch/source/monotouch/src/uikit/uitextfield.g.cs:919    @ virtualnax.virtualnaxviewcontroller.sendpost (iasyncresult result) [0x00031] in /users/emil/projects/virtualnax/virtualnax/virtualnaxviewcontroller.cs:69    @ system.net.webasyncresult.cb (system.object unused) [0x00000] in /developer/monotouch/source/mono/mcs/class/system/system.net/webasyncresult.cs:151  

on line 68 is:

post.write("email=" + username.text + "&password=" + password.text + "&remember=on&redir=index.php%2fprofile%2f&action=login&submit=+log+in+"); 

if needed here of code it:

public void senddata() {      httpwebrequest web = (httpwebrequest)webrequest.create(dataurl);     web.contenttype = "application/x-www-form-urlencoded";     var cookies = new cookiecontainer();     web.method = "post";     web.cookiecontainer = cookies;     web.begingetrequeststream(new asynccallback(sendpost), web); }  void sendpost(iasyncresult result) {     httpwebrequest web = (httpwebrequest)result.asyncstate;     var post = new streamwriter(web.endgetrequeststream(result));       post.write("email=" + username.text + "&password=" + password.text + "&remember=on&redir=index.php%2fprofile%2f&action=login&submit=+log+in+");     post.close();     web.begingetresponse(new asynccallback(getdata), web); }   void getdata(iasyncresult result) {     httpwebrequest web = (httpwebrequest)result.asyncstate;      string forside = new streamreader(web.endgetresponse(result).getresponsestream()).readtoend();      forside = webutility.htmldecode(forside);      if (forside.contains ("welcome back")) {         nsuserdefaults.standarduserdefaults.setstring ("sandt", "logind");         this.performsegue ("tomain", this);     } else if (forside.contains ("<div id=\"login_fail\">")) {         using (uialertview alert = new uialertview ("error", "the entered information incorrect.\n\nplease try again", null, "ok", null)) {             alert.show ();         }     } else {         using (uialertview alert = new uialertview ("error", "an unexpected error has occured.\n\nplease try again later", null, "ok", null)) {             alert.show ();         }     } } 

if 'username' , 'password' ui controls, cannot access them background thread. need values , store them in class variables (or pass them parameters) before call method.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -