某些命令(例如httpClIEnt或httpPost)不起作用.有人可以帮我吗?
@OverrIDe protected users doInBackground(VoID... params){ Map<String, String> dataToSend = new HashMap<>(); dataToSend.put("x", users.x + ""); dataToSend.put("y", users.y); URL url = new URL(SERVER_ADRESS); httpURLConnection conn = (httpURLConnection) url.openConnection(); httpParams httpRequestPramas = new BasichttpParams(); conn.setConnectionTimeout(httpRequestPramas, CONNECTION_TIME); httpconnectionParams.setSoTimeout(httpRequestPramas, CONNECTION_TIME); httpClIEnt clIEnt = new DefaulthttpClIEnt(httpRequestPramas); httpPost post = new httpPost(SERVER_ADRESS + "login.PHP"); users returnedusers = null; try { post.setEntity(new UrlEncodedFormEntity(dataToSend)); httpResponse httpResponse = clIEnt.execute(post); httpentity entity = httpResponse.getEntity(); String result = EntityUtils.toString(entity); JsONObject jObject = new JsONObject(result); if (jObject.length() == 0){ users = null; }else{ String vorname = jObject.getString("y"); int kundennummer = jObject.getInt("x"); returnedusers = new users(users.y, users.x); } }catch (Exception e){ e.printstacktrace(); } return returnedusers; }
谢谢您的帮助.
解决方法:
试试这个
URL url = new URL("http://example.sitedemo.service.PHP");httpURLConnection conn = (httpURLConnection) url.openConnection();conn.setRequestMethod("POST");Uri.Builder builder = new Uri.Builder().appendqueryParameter("username", "maven") .appendqueryParameter("password", "123");String query = builder.build().getEncodedquery();OutputStream os = conn.getoutputStream();BuffereDWriter writer = new BuffereDWriter(new OutputStreamWriter(os, "UTF-8"));writer.write(query);writer.flush();writer.close();os.close();conn.connect();inputStream in = new BufferedinputStream(conn.getinputStream());response = IoUtils.toString(in, "UTF-8");
编号-android.net.Uri.Builder
总结以上是内存溢出为你收集整理的Java-Android Studio-像httpparams,httpclient这样的旧命令不再起作用全部内容,希望文章能够帮你解决Java-Android Studio-像httpparams,httpclient这样的旧命令不再起作用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)