Https Post Request Not Working in Android -
I am attempting to enter a website, by sending an HTTP post request and getting the source code for the next page After login "Android" i'v watches too many videos but nothing works: do any of these help in this code:
The public class increases the main activity activity (textual text; @ Override protected zero creation (bundle saved inst Sustainate) {Super. NET (SENDED INSTEST STATES); setContentView (R.layout.activity_main); Text = (TextView) Find VViBID (RTTEV2); {New DownloadSourceCodeTask () ("Link");} hold (exception e) {GetApplicationContext (), "main in error", toast.LNNHNHLANG) Show ();}} PrivateInststream Open HTTP connection (string URL) IOException Throws {InputStream in = null; acute reaction = -1; Rl url = new url (url); url connection connection = url.openConnection (); if (! (HTTPL connection) for example new IOException ("no HTTPS connection"); Try {HttpURLConnection httpConn = (HttpURLConnection) conn; String Param = "ssousername =" + URLEncoder.encode ("Username", "UTF-8") + "Password =" + URLNcoder Encoded ("Quality of Password", "UTF-8"); HttpConn.setDoOutput (true); HttpConn.setAllowUserInteraction (wrong); HttpConn.setInstanceFollowRedirects (true); HttpConn.setRequestMethod ("Post"); HttpConn.setFixedLengthStreamingMode (. Param.getBytes ()); HttpConn.setRequestProperty ("content-type", "text / html; charset = windows-1256"); HttpConn.connect (); Response = httpConn.getResponseCode (); If (feedback == HttpURLConnection.HTTP_OK) {in = httpConn.getInputStream (); }} Hold (exception e) {log d. ("Networking", E.A.T.T.O.K.K.Lized Message ()); } Return; } Private string DownloadSourceCode (string URL) {int BUFFER_SIZE = 2000; InputStream Inn = Null; Try it in {OpenHttpConnection (url); } Grip (IOE EXPRESS E) {Log D. ("Error in Connection", E.A.L.C.C.Lized Message ()); Return ""; } InputStreamReader isr = new InputStreamReader (in); Int charRead; String str = ""; Four [] inputbuffer = new four [buffeasia]; Try {while ((charRead = isr.read (inputBuffer)); gt; {string string = string; Str + = readString; Inputbufr = new four [BUFFER_SIZE]; } In.close (); } Grip (IOE EXPRESS E) {Log D. ("Error in Connection", E.A.L.C.C.Lized Message ()); Return ""; } Return str; } Private class DownloadSourceCodeTask enhances AsyncTask & lt; String, zero, string & gt; {Progressive Dialog Dialog; Protected string doInBackground (string ... url) {DownloadsSourceCode (url [0]); } @ Override Protected Zero on Prextech () {dialog = Progressiveog} Show (Main activation. This, "", "Loading, please wait ...", is true); } Zero on secure expression (string result) {if showing (dialog.is ()) {dialog.cancel (); } Text. Set text (results); }}}
a '& amp; Before password parameter, adding 2 lines after connect () and changing encoding in UTF-8 in content-type. Check out the new code below:
Try {HTPL connection connection httpConn = (HttpURLConnection) conn; String Param = "ssousername =" + URLEncoder.encode ("Username", "UTF-8") + "and password =" + URLNcoder.exode ("passwordview", "UTF-8"); HttpConn.setDoOutput (true); HttpConn.setAllowUserInteraction (wrong); HttpConn.setInstanceFollowRedirects (true); HttpConn.setRequestMethod ("Post"); HttpConn.setFixedLengthStreamingMode (. Param.getBytes ()); HttpConn.setRequestProperty ("content-type", "text / html; charset = windows-1256"); HttpConn.connect (); . Write httpConn.getOutputStream () (param.getBytes ()); HttpConn.getOutputStream () flush () .; Response = httpConn.getResponseCode (); If (feedback == HttpURLConnection.HTTP_OK) {in = httpConn.getInputStream (); }} Hold (exception e) {log d. ("Networking", E.A.T.T.O.K.K.Lized Message ()); } Hope it helps.
Comments
Post a Comment