1

I have an end point of HTTP DELETE method. I want to pass some headers, more specifically Content-Type=application/x-www-form-urlencoded. Also there are some parameters based on which at server side it will be decided which record should be deleted. And Server Implementation is not accessible to me.

I am using apache HTTP client. My method for HTTP DELETE is as follow :

private String doDelete(String url, Map<String,String> params, Map<String,String> headerMap){

    HttpClient httpClient = new DefaultHttpClient(httpParams);
    HttpDelete httpDelete = new HttpDelete(httpRequestWrapper.getUrl());

    if(headerMap != null){
        for(String headerName : headerMap.keySet()){
            httpDelete.addHeader(headerName, headerMap.get(headerName));
        }
    }
    
    if(params != null){         
        for(String paramName : params.keySet()){
            httpParams.setParameter(paramName, params.get(paramName));
        }
        httpDelete.setParams(httpParams);
    }
    
    HttpResponse httpResponse = httpClient.execute(httpDelete);
    HttpEntity httpEntity = httpResponse.getEntity();
    String responseStr = getASCIIContentFromEntity(httpEntity);
    return responseStr; 
}

The problem is, I am seeing (In Debug Mode) that parameters are correctly being passed in delete request from my end. But at server end parameters are received blank. Is there any way I can pass parameters & headers successfully?

Any help is appreciated.

1 Answer 1

1

Passing the headers through verbatim may cause problems.

With the above in mind, be advised that, as implemented, the HttpDelete method does not take a body so having that particular Content-Type header associated with your request may be causing interference confusing the container.

Try omitting the header from the client containing Content-Type and see if that resolves your issue.

EDIT AH!! Found the issue! The setParams method is confusing. According to the documentation from HTTP Client 4.x

Provides parameters to be used for the processing of this message.

The parameters you're setting in your code will not be passed because they are being conveyed to the underlying client executing the request.

This SO article defines the appropriate approach for what you're attempting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.