admin
   
مدیریت
ارسالهاAsnwers : | 7206 |
عضویتRegistration date : | 18 /10 /1390 |
حمایت کردهthanks : | 4361 |
حمایت شدهThanked : | 3281 |
|
پاسخAnswer 39 : --- چت روم ---
کد:
package com.company; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; public class Main {
public static void main(String[] args) throws IOException, ParseException {
URL url = new URL("http://192.168.0.103/test/android_test.php"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); String sec_code = "13613843513541354254125413541354354354135413541351"; String data = String.format("sec_code_contact=%s", URLEncoder.encode(sec_code, "UTF-8")); // System.out.println(data); connection.setDoOutput(true); connection.setRequestMethod("POST"); // connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("Content-Length", String.valueOf(data.length())); connection.getOutputStream().write(data.getBytes()); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String code = "", line; while ((line = reader.readLine()) != null) code += "\n" + line; if(code.length() > 0) code = code.substring(1); reader.close(); JSONParser parser = new JSONParser(); Object json = parser.parse(code); JSONObject array = (JSONObject) json; System.out.println(array.get("one")); } }
|