无法解析writeStream-HTTPConnection POST

时间:2018-06-23 15:19:24

标签: java android httpurlconnection androidhttpclient

我正在尝试从Java-Android Studio发布到RESTful api,并且由于某种原因,IDE无法解析HttpUrlConnection中的“ writeStream(output)”

        /* POSTING TO RESTful API */
    URL url = null;
    try {
        url = new URL("http://kz.test/api/v1/reports");
        // Open the HTTP connection to the website
        HttpURLConnection client = (HttpURLConnection) url.openConnection();
        client = (HttpURLConnection) url.openConnection();
        //Set a request to POST
        client.setRequestMethod("POST");
        // Todo: SET Value's to each Key posting to.
        client.setRequestProperty("KEY","VALUE");
        client.setDoOutput(true);
        //Output the info to the server (the stream) then remove and close stream
        OutputStream outputPost = new BufferedOutputStream(client.getOutputStream());
    writeStream(outputPost); //Todo: fixme writeStream

        outputPost.flush();
        outputPost.close();
        // And close HTTP connection...
        if(client != null) // just in case
        {
            client.disconnect();
        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (ProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

您知道是什么原因造成的吗? 预先感谢大家!

0 个答案:

没有答案
相关问题