Add Custom Header Data to Android HTTP request

2019-05-20 08:32发布

问题:

I'm going to be making HTTP requests in an android application. There is some custom header data that I'd like to add. Specifically, I'm going to be using tickets to track authorized requests (I'm doing this so I can keep things RESTful). I'd like be able to basically add this to the HTTP header

ticketId : someTicketId

What is the simplest way to do this in android?

回答1:

This function looks like it will do the trick.



回答2:

Brians is certainly correct for if you wanna use the apache stack. If you however want to use HttpURLConnection, this function will also do the trick.