I am trying to perform the OAuth 1.0a authentication flow using Java. OAuth 1.0a requires "All parameter names and values [to be] escaped using the RFC3985 percent-encoding mechanism... Text names and values MUST be encoded as UTF-8 octets." I would like to use the HttpsURLConnection class and use the setRequestProperty method to add the oauth parameters to the Authentication header. However, Java internally stores strings with UTF-16 encoding. I built a method that performs the percent encoding for me, so the string "Hello World!" is successfully changed to "Hello%20World%21". Even though it follows percent-encoding, it is still internally stored in UTF-16. If I pass this string into the setRequestProperty under an arbitrary key, this would be unreadable to a server accepting UTF-8 data. How do I add UTF-8 text to an HTTP header? The setRequestProperty method takes two Strings, so no matter what, I can only pass in data stored in UTF-16. I have also converted the text data to a byte array that is in UTF-8 format, but I cannot use an array as input to the setRequestProperty.
Related Questions in JAVA
- I need the BIRT.war that is compatible with Java 17 and Tomcat 10
- Creating global Class holder
- No method found for class java.lang.String in Kafka
- Issue edit a jtable with a pictures
- getting error when trying to launch kotlin jar file that use supabase "java.lang.NoClassDefFoundError"
- Does the && (logical AND) operator have a higher precedence than || (logical OR) operator in Java?
- Mixed color rendering in a JTable
- HTTPS configuration in Spring Boot, server returning timeout
- How to use Layout to create textfields which dont increase in size?
- Function for making the code wait in javafx
- How to create beans of the same class for multiple template parameters in Spring
- How could you print a specific String from an array with the values of an array from a double array on the same line, using iteration to print all?
- org.telegram.telegrambots.meta.exceptions.TelegramApiException: Bot token and username can't be empty
- Accessing Secret Variables in Classic Pipelines through Java app in Azure DevOps
- Postgres && statement Error in Mybatis Mapper?
Related Questions in URLENCODE
- How send urlencoded in Postman object[ ] and send to JSa via axios
- How to encode/decode a URL string in TMS WEB Core using Delphi?
- How to fix URLEncoder related issues?
- How to encode parameters for AWS API Gateway (HTTP API)?
- How can I target multiple URLs, using a single form and keyword?
- How to encode a MultiIDict in werkzeug 3.0
- Urls in email body is not showing as hyperlink when we prepopulate the content in new outlook
- Replace question mark in URL using .htaccess
- Files with special characters in their file name load locally but not live
- Submitting NVD API CVE Search by cpeName with special characters
- Cannot match any routes. for encoded url
- Routing encoded url in angular
- Querying postgrest with httpx
- Unable to Extract Resource Links from Public Google Drive Folder
- Result of encodeURIComponent not being decoded correctly on server-side
Related Questions in OAUTH-1.0A
- OAuth1.0 Using NodeJS and Axios - 401 Error (Authorization Header)
- Integration of Netsuite oAuth 1.0 Get API with HTTPCLIENT
- Unable to connect to NetSuite REST from Power Query
- OAuth 1.0 Authentication from .net core 6.0 rest api always responds Invalid Signature
- Getting 409 conflict error in OAuth 1 when using an API in C#
- One-Legged oAuth in C# using RestSharp
- Can you use a HMAC-SHA256 signature in authlib in python?
- RestSharp OAuth1 Method.Options will not authenticate with NetSuite REST
- Netsuite rest API for upsert is responding with 401 response code intermittently
- 401 error for netsuite REST upsert operation via TBA in node js
- How do I make a call from Azure API Management to an external API with OAuth 1.0
- Correct format for a Base Encryption string for Oauth 1.0 for a PATCH request
- OAuth1 implementation using requests library in Python
- Python OAuth1.0 using consumer key and RSA private key
- Generating OAuth 1.0 signatures with PHP core code leads to 'invalid signature' error - any ideas?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
You are overthinking it. The way java stores strings internally is completely irrelevant to the matter and is transparent to you as a programmer. Just set your string as a header value and it will work. I wrote my own simplified Http client based on
HttpsURLConnectionclass and I used it it to set auth header for authentication as well as many other headers and it works just fine. Here is a Javadoc for my HttpClient and here is a GitHub page for my MgntUtils Library. There you can see the source code. Here is the HttpClient class source code. See the line 344.