这里有一个很好的例子。在下面的Powerlord正确的地方,您需要POST。
HttpURLConnection
下面是执行此 *** 作的代码,
URL url = new URL(urlString); URLConnection conn = url.openConnection(); conn.setDoOutput(true); conn.setRequestProperty ("Authorization", enpredCredentials); OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream()); writer.write(data); writer.flush(); String line; BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); while ((line = reader.readLine()) != null) { System.out.println(line); } writer.close(); reader.close();
URLConnection为
HttpURLConnection,使其成为POST请求。
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST");
建议(…中的评论):
您可能还需要设置这些属性,
conn.setRequestProperty( "Content-type", "application/x-www-form-urlenpred");conn.setRequestProperty( "Accept", "*/*" );
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)