简体   繁体   English

在get中发送我的SIM卡的价值

[英]Send value of my sim card in get

I would like to recover the values of my sim card to send it as a get or post to my app php I read several topic and I try a lot of things but I am novice in java. 我想恢复我的SIM卡的值,以将其作为get或post发送到我的应用php中,我读了几个主题,尝试了很多事情,但是我是java的新手。 And I dont know how to send data taken from my java application to my web site. 而且我不知道如何将从Java应用程序获取的数据发送到我的网站。

String IMEINumber = manager.getDeviceId();
String SIMSerialNumber = manager.getSimSerialNumber();

BtnStart = (Button) findViewById(R.id.idBtnStart);
varText = (TextView) findViewById(R.id.idTxtView);
varText.setText(info);

I try this without succes: 我尝试不成功:

URL url = new URL( "http://www.example.com/erm**?data=SIMSerialNumber**");
HttpURLConnection connexion = (HttpURLConnection) url.openConnection();

Try using below code snippet: Code for Post request in java, sending request to specified URL. 尝试使用以下代码段: Java中Post请求的代码,将请求发送到指定的URL。

        HttpURLConnection connection = null;
        JSONObject responseJsonObject = null;
        try {

            URL posturl = new URL("http://www.example.com/erm**?data=SIMSerialNumber**");
            connection = (HttpURLConnection) posturl.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "<type of your content>");
            connection.setDoInput(true);
            connection.setDoOutput(true);

            //Send request
            DataOutputStream wr = new DataOutputStream(connection.getOutputStream());

postBody -- will contain your value to be posted. postBody-将包含您要发布的值。

            wr.write(postBody.toString().getBytes("UTF-8"));
            wr.flush();
            wr.close();

            InputStream is = connection.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(is));
            String line;
            StringBuffer response = new StringBuffer();
            while ((line = rd.readLine()) != null) {
                response.append(line);
                response.append('\r');
            }

            rd.close();

Save your response in any format you want.I'm using Json format 以您想要的任何格式保存您的回复。我使用的是Json格式

            responseJsonObject = new JSONObject(response.toString());

        } catch (Exception e) {
            e.printStackTrace();
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM