Hello, gentlemen! I worked here with the API of the disk, everything went well until the authorization was sent from outside the SDK. Here they are asked to do this:

The resulting token should be passed in the Authorization header each time the Disk API is called, indicating the type of the token before its value. An example of such a header: Authorization: OAuth 0c4181a7c2cf4521964a72ff57a34a07

It would be good, but:

connection.setRequestMethod("POST"); connection.addRequestProperty("Authorization: OAuth", "0c4181a7c2cf4521964a72ff57a34a07"); 

Give an error:

 java.lang.IllegalArgumentException: Illegal character(s) in message header field: Authorization: OAuth 

I understand that there is a mistake, but I can’t think of something from the morning how to solve it, because I have never transmitted almost any headers. Who can, prompt the decision, please. Thank you in advance!

Corrected code:

 connection.addRequestProperty("Authorization", "OAuth 0c4181a7c2cf4521964a72ff57a34a07"); 
  • Russian letters in the title is not very, try encode or something. - pavel
  • Yes, this is me, for example, so that the token does not shine :) Now I’ll change it to normal ... - Flerry
  • Space is also a bad character ...% 20 or something like this should be - pavel
  • Heh. Did this: - Flerry
  • URLEncoder.encode ("Authorization: OAuth", "UTF-8") Wrote now that "Method is not allowed" - Flerry

1 answer 1

Actually, the answer was formed on the basis of these two questions:

In my code, the error is:

setRequestMethod ("POST");

There is no need to do POST, you can not even specify the exact type of request

and in:

"Authorization: OAuth", "0c4181a7c2cf4521964a72ff57a34a07"

Here this form of recording gives two errors:

  • ":" is not perceived
  • OAuth must be in the key

All errors above corrected, I hope someone will help later :)