No SDK is required to call the Turing Robot method!!!

The call of the Turing robot is actually when you send a text message to the server, and he returns you one, which looks like a human conversation.

I don’t know why it is so troublesome to get an SDK. The previous interface official website is no longer available, but it can still be used. The returned JSON is JSON but I am too lazy to parse it. Anyway, the format is fixed, just treat it as a string, simple!

String data = null;
                            try {
                                //Be sure to turn it into utf-8
                                data=URLEncoder.encode(edit.getText().toString(), "utf-8");
                            } catch (UnsupportedEncodingException e) {
                                e.printStackTrace();
                            }
 
                            String strUrl = "http://www.tuling123.com/openapi/api?key=2e29921641b808e1986e20d4fc6e3238&info=+"+data;
//The key is your own registration, of course you can use mine directly
 
                            URL url = null;
                            try {
                                url = new URL(strUrl);
 
                                HttpURLConnection conn = null;
 
                                conn = (HttpURLConnection)url.openConnection();
 
                                conn.setRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko");
 
                                conn.connect();
                                //Open the input stream of this page, the content of this website is returned in the form of byte stream. If it is a web page, it will return html, and the picture will return the content of the picture.
                                InputStream inStream = conn.getInputStream();
 
                                byte [] buf = new byte[1024];
 
                                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
 
                                int n = 0;
 
                                while((n=inStream.read(buf))!=-1){
 
                                    outStream.write(buf,0,n);
 
                                }
 
                                inStream.close();
                                outStream.close();
 
//Use ByteArrayOutputStream to buffer it and convert it to String again, otherwise there will be garbled problems in the space
 
                                String result = outStream.toString();
//The returned JSON, after making it into a string, remove the head and tail
                                result = result.substring(23,result.length()-2);

Leave a Comment

Your email address will not be published.

Scroll to Top