Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected char 0x0a at 28 in header value #1153

Closed
prashantwosti opened this issue Oct 1, 2015 · 6 comments
Closed

Unexpected char 0x0a at 28 in header value #1153

prashantwosti opened this issue Oct 1, 2015 · 6 comments

Comments

@prashantwosti
Copy link

This is my header value: I99Uy+HjG5PpEhmi8vZgm0W7KDQ=

When I try to pass that value via parameter, retrofit is throwing an error.
I/: Failure: Unexpected char 0x0a at 28 in header value: I99Uy+HjG5PpEhmi8vZgm0W7KDQ=
But when I add the same header value as hard-coded string in API interface class, it works.

This works:

@Headers({
"Content-Type: application/json",
"app-key: I99Uy+HjG5PpEhmi8vZgm0W7KDQ="
 })
@POST("login/facebook")
Call<LoginResponse> postFacebookData(@Body FacebookRequest request);

This does not:

@Headers({
"Content-Type: application/json"
})
@POST("login/facebook")
Call<LoginResponse> postFacebookData(
@Header("app-key") String hashKey,
@Body FacebookRequest request
);

Retrofit retrofit = RetrofitAdapter.getAdapter();
FacebookLoginAPI loginAPI = retrofit.create(FacebookLoginAPI.class);
-> loginAPI.postFacebookData("I99Uy+HjG5PpEhmi8vZgm0W7KDQ=", facebookRequest).enqueue(new Callback<LoginResponse>() {

How do I fix it?

Thanks

@JakeWharton
Copy link
Member

0x0a is a newline character which is forbidden in a header (by OkHttp, not Retrofit). Ensure these control characters are stripped before passing them to Retrofit.

@prashantwosti
Copy link
Author

Thanks. So that means "=" is causing all the trouble here?

@JakeWharton
Copy link
Member

No, there's an invisible newline character (\n) after the "=". The "=" is character 27.

@prashantwosti
Copy link
Author

Thanks. .trim() did the job. :)

@drindt
Copy link

drindt commented Feb 23, 2016

@prashantwosti Another way could be:
Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
this avoids wrapping with a platform specific newline character(s).

@sawepeter
Copy link

0x0a is a newline character which is forbidden in a header. Solution would be to make sure that these characters are stripped off before sending the encoded value as header.

Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP); this avoids wrapping with a platform specific newline character(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants