Skip to content

Please support HTTP DELETE request #4

@metalik

Description

@metalik

Some of the Graph APIs require HTTP DELETE request but the current plugin only support GET and POST. I try modifed the existing FacebookGraphService.makeRequest(urlAsString, params) as follow and seems it's working fine:

private def makeRequest(urlAsString, params) {
    def resp
    def encodedParams = ""
    URL url
    Writer writer
    URLConnection connection

    // Encoding the params...
    if (params) {
        params.each{k,v ->
            if(k != 'method' && k != 'id') {
                encodedParams += k.encodeAsURL() + '=' + v.encodeAsURL() + '&'
            }
        }
        encodedParams = encodedParams[0..-2]
    }

    try {
        // Making the request
        switch(params.method) {
            case "GET":
                if(encodedParams) urlAsString += '?' + encodedParams
                url = new URL(urlAsString)
                resp = url.text
            break;
            case "POST":
            case "DELETE":
                url = new URL(urlAsString)
                connection = url.openConnection()
                connection.setRequestMethod(params.method)
                connection.doOutput = true

                writer = new OutputStreamWriter(connection.outputStream)
                writer.write(encodedParams)
                writer.flush()
                writer.close()
                connection.connect()

                if (connection.responseCode == 200 || connection.responseCode == 201)
                    resp = connection.content.text

            break;
        }
    } catch(Exception e) {
        // resp will be null, nothing to do...
        log.error(e)
    }

    return resp
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions