标签:blog http io ar os java sp on 2014
============问题描述============
public class HttpAssist { public static String doPost(JSONObject json) throws IOException{ URL postUrl = new URL(Config.url); HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection(); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestMethod("POST"); connection.setUseCaches(false); connection.connect(); OutputStreamWriter out = new OutputStreamWriter (connection .getOutputStream()); out.write( Config.getParameterName + "=" + json.toString()); out.flush(); out.close(); // flush and close BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"utf-8")); String line=""; String res = ""; while ((line = reader.readLine()) != null){ res += line; System.out.println(line); } reader.close(); connection.disconnect(); return res; } }
============解决方案1============
============解决方案2============
HttpURLConnection中connection.getInputStream()报异常FileNotFoundException
标签:blog http io ar os java sp on 2014
原文地址:http://www.cnblogs.com/yiguobei99/p/4089443.html